I have a plugin architecture, where I call functions in a dynamic library and they return me a char*
which is the answer, it is used at some later stage.
This is the signature of a plugin function:
char* execute(ALLOCATION_BEHAVIOR* free_returned_value, unsigned int* length);
where ALLOCATION_BEHAVIOR
must be either: DO_NOT_FREE_ME
, FREE_ME
, DELETE_ME
where the plugin (in the library) tells me how the plugin allocated the string it has just returned: DO_NOT_FREE_ME
tells me, this is a variable I'm not supposed to touch (such as a const static char*
which never changes) FREE_ME
tells me I should use free()
to free the returned value and DELETE_ME
tells me to use delete[]
to get rid of the memory leaks.
Obviously, I don't trust the plugins, so I would like to be able to check that if he tells me to free()
the variable, indeed it is something that can really be freed ... Is this possible using todays' C/C++ technology on Linux/Windows?