Allocating and Deallocating memory across shared lib boundaries
As long as you stick with Glibc or other "normal" allocators (jemalloc, tcmalloc, etc.) the heap state will be shared by all libraries and thus you'll be able to free memory allocated somewhere with malloc
anywhere you want.
In theory it may be possible to circumvent this. For example some library may be linked with custom implementation of malloc
/free
(via symbol scripts trickery of -Bsymbolic
) which has it's own private heap and thus will not interact well with other parts of your program. But I've never seen anything like this in real life.
STL containers are based on malloc
/free
so it is possible to pass/modify them across library boundaries as well. Of course different libraries may be compiled with different compilers and different incompatible versions of STL (e.g. libstdc++, libcxx, etc.) but their C++ container types would be different and compiler simply would not allow you to pass them across incompatible modules.