Skip navigation

QuickLook and overriden new/delete operator

1648 Views 5 Replies Latest reply: Dec 10, 2010 3:35 PM by etresoft RSS
MoepMoep Calculating status...
Currently Being Moderated
Dec 9, 2010 6:05 PM
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
  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Dec 9, 2010 7:00 PM (in response to MoepMoep)
    Most likely, that library is just buggy.
    MacBook 2007 (white), Mac OS X (10.6.5), + iMac 27" + iPad + MacBook Pro
  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Dec 10, 2010 1:51 PM (in response to MoepMoep)
    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.
    MacBook 2007 (white), Mac OS X (10.6.5), + iMac 27" + iPad + MacBook Pro
  • etresoft Level 7 Level 7 (23,905 points)
    Currently Being Moderated
    Dec 10, 2010 3:35 PM (in response to MoepMoep)
    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.
    MacBook 2007 (white), Mac OS X (10.6.5), + iMac 27" + iPad + MacBook Pro

Actions

More Like This

  • Retrieving data ...

Bookmarked By (0)

Legend

  • This solved my question - 10 points
  • This helped me - 5 points
This site contains user submitted content, comments and opinions and is for informational purposes only. Apple disclaims any and all liability for the acts, omissions and conduct of any third parties in connection with or related to your use of the site. All postings and use of the content on this site are subject to the Apple Support Communities Terms of Use.