Free-ing pointers returned from shared libraries compiled with different compiler

Hi, I am new to C++ and UNIX programming!

I have a question. Is it safe for me to free a pointer returned by a library compiled using a different compiler? If so, why is the case?
My system is x86_64 Ubuntu 16.04, and the library was compiled using GCC 6, whereas my program is compiled using clang 3.8.

P.S.: the library is XCB (X11 C Binding). It returned pointers to data structures, but expect the app to free the pointers. The problem is that the library doesn't provide any 'free' function.
What about "new"/"delete"? Does the actual implementation differs between compilers?
It happens sometimes that memory allocations and frees of different compilers are incompatible, but on Linux there should be no such problems, especially between gcc and clang.
Last edited on
Is it safe for me to free a pointer returned by a library compiled using a different compiler?

Probably not.

What about "new"/"delete"?

new/delete do their thing, i.e. allocate/release memory and call constructor/destructor. That isn't the problem.

The problem is making sure they're using the same heap.

Typically, this can be resolve using methods in the library, like create/release. I posted an example in this forum some time back. I'll see if I can find it.

EDIT:
http://www.cplusplus.com/forum/general/33662/

You need a release() method with these examples.
http://www.cplusplus.com/forum/general/35380/
http://www.cplusplus.com/forum/unices/184342/
Last edited on
Topic archived. No new replies allowed.