I've looked all over for an answer to this but can't seem to find one. (I have fairly limited experience with C++)
In my library, I free a string. (Amazing, huh?)
This is where the problem arises. I have a struct which contains a char* that may be allocated on the heap or may not be. While it is a valid pointer it cannot be freed.
IE
char* s1 = "A String";
char* s2 = (char*)memcpy(malloc(9), s1, 9);
free(s2);
free(s1);
Will cause an error on "free(s1);" (As it should) Because s1 does not actually need to be freed, (It isn't on the heap) how can I handle this in an "acceptable" way? (On similar topics the answer of "let it crash" didn't seem reasonable IMO)
Because the struct is not solely created by the library, it is not possible to guarantee that a string will be properly copied over using something like memcpy.
Seeing as this is a windows library, I don't need to worry about using ISO C stuff or standard C functions.