5 Replies Latest reply: Dec 10, 2010 3:35 PM by etresoft
MoepMoep Level 1 Level 1 (0 points)
Hi at all,

I need your !great! help. Currently I am on the way to write a QuickLook plugin.
To do that, I use a static lib in the project to get certain information of the file.

Everything works fine, except the QuickLook plugin crashs on exit. The new and delete operator are overriden by the external lib.

The problem is, it seems that OSX allocates some internal stuff with the
original new operator and deallocates it with the +new overriden+ delete
operator which occurs a crash.

Any ideas how to solve that? The overriden new operator is in its own namespace.

Each help is highly appreciated

Bye,

moepmoep

Mac OS X (10.6.5), Macbook Pro
  • 1. Re: QuickLook and overriden new/delete operator
    etresoft Level 7 Level 7 (24,270 points)
    Most likely, that library is just buggy.
  • 2. Re: QuickLook and overriden new/delete operator
    MoepMoep Level 1 Level 1 (0 points)
    No, the library is well tested and not buggy. It simply overrides the new/delete operator
    and in some calls the delete operator gets some pointers where the corresponding new operator did
    not allocated the memory. Just to remember, the operators are in their own namespace.

    Any ideas what might be wrong?
  • 3. Re: QuickLook and overriden new/delete operator
    etresoft Level 7 Level 7 (24,270 points)
    MoepMoep wrote:
    No, the library is well tested and not buggy. It simply overrides the new/delete operator
    and in some calls the delete operator gets some pointers where the corresponding new operator did
    not allocated the memory.


    That sounds like a bug to me.

    Apple (or, rather, gcc) is free to do any clever things it wants inside its own new/delete operators. If some library wants to write their own, they don't have to emulate anything that Apple does. The old C malloc still works great. But if you have some pointer to memory that did not come from a valid malloc call, you better not call free on it.

    Keep in mind that many open source projects are built and tested only on Linux. Linux is notorious for doing everything in its power to make bad code run. Then, people take this running and tested code and try it on MacOS X and it fails. "But it runs great on Linux!" they proclaim. That is true, but only because malloc never fails on Linux. If your programs runs out of memory on Linux, Linux will kill some other, random program. On MacOS X, malloc may fail and developers need to check for that.
  • 4. Re: QuickLook and overriden new/delete operator
    MoepMoep Level 1 Level 1 (0 points)
    Thanks for your response! But I can't still see a bug in here. Let me try to explain in a very short way what happens:

    The delete operator doesn't really crash if I just change some lines in the delete operator and fix the redirection to free(..) it would work fine. I just noticed that the memory which is passed to this delete operator was not allocated by the overriden new operator.

    So, why is this a problem? I could simply ignore it because after this function the memory is freed by the OS anyway and with a fingerprint in the allocated memory I could check if its allocated by the new operator, but I thought something special is going on here but IMHO this is not the way I normally fix that stuff.

    Bye,

    moepmoep
  • 5. Re: QuickLook and overriden new/delete operator
    etresoft Level 7 Level 7 (24,270 points)
    MoepMoep wrote:
    The delete operator doesn't really crash if I just change some lines in the delete operator and fix the redirection to free(..) it would work fine. I just noticed that the memory which is passed to this delete operator was not allocated by the overriden new operator
    So, why is this a problem?


    Because it's wrong

    I could simply ignore it because after this function the memory is freed by the OS anyway and with a fingerprint in the allocated memory I could check if its allocated by the new operator, but I thought something special is going on here but IMHO this is not the way I normally fix that stuff.


    Sorry, but I don't follow. What library is this? If people could actually see the code it would make much more sense.