[Qt-interest] Replace Qt Allocator
Eric Clark
eclark at ara.com
Wed Sep 16 16:31:42 CEST 2009
Hello All,
Our program uses a system allocator called nedmalloc. We override the new and delete operators to use this system allocator. However, after porting to Qt 4 we have ran into some issues with the QList class and it's destructor. When the list is destructed, it attempts to free the memory created by the list, but nedfree() crashes because the memory was instantiated using the system allocator, malloc(). Here is the problem:
The problem is indeed a violation of the ODR requirement in the ISO C++ spec. For example in this line:
QModelIndexList indexes = list->selectionModel()->selectedRows();
QModelIndexList exists in the local binary due to being a templated type based on QList, therefore its destructor is called from the local binary where ::operator delete has been defined to invoke nedmalloc. Unfortunately the initial constructor of the list (selectedRows()) exists in one of the Qt DLL binaries where ::operator new is defined to invoke the system allocator. Therefore the list is being constructed with the system allocator and destructed with nedmalloc - this obviously enough provokes a segfault as ODR is violated.
I was told by some guys on this interest board that I should build nedmalloc into Qt. However, after doing so, I still get the same error. What I did to build nedmalloc into Qt, was I modified the body of qFree(), qMalloc(), and qRealloc() to use nedfree(), nedmalloc(), and nedRealloc() respectively. This apparently was not enough to fix the problem. Could anyone tell me what else needs to be done? Do I need to override the new and delete operators in Qt as well? Are there any direct calls to malloc() in the code that I am unaware of?
Any help with this would be greatly appreciated!
Eric
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20090916/38387cf6/attachment.html
More information about the Qt-interest-old
mailing list