new in dll, delete in exe, bang :(
-
hi, i'm writing a (legacy, non-MFC) dll and there might get an exception thrown in there. it is caught in the exe-file that uses that dll. dll:
//some error throw new CSomeException();
exe:catch (CSomeException *e) { e->SomeFunction(); // works fine delete e; // crash }
the delete-call crashes because the object is not a valid *local* heap-pointer. stepping in dbgheap.c reveales the following passage/* * If this ASSERT fails, a bad pointer has been passed in. It may be * totally bogus, or it may have been allocated from another heap. * The pointer MUST come from the 'local' heap. */ _ASSERTE(_CrtIsValidHeapPointer(pUserData)); // fails
so, finally. how am i supposed to handle this? i mean throwing an exception in a library isn't that uncommon, is it? :confused: :wq -
hi, i'm writing a (legacy, non-MFC) dll and there might get an exception thrown in there. it is caught in the exe-file that uses that dll. dll:
//some error throw new CSomeException();
exe:catch (CSomeException *e) { e->SomeFunction(); // works fine delete e; // crash }
the delete-call crashes because the object is not a valid *local* heap-pointer. stepping in dbgheap.c reveales the following passage/* * If this ASSERT fails, a bad pointer has been passed in. It may be * totally bogus, or it may have been allocated from another heap. * The pointer MUST come from the 'local' heap. */ _ASSERTE(_CrtIsValidHeapPointer(pUserData)); // fails
so, finally. how am i supposed to handle this? i mean throwing an exception in a library isn't that uncommon, is it? :confused: :wqI bet at least one of your modules (exe or dll) has CRT statically linked. That means that one instance of CRT is allocating the memory and another one tries to release it ... BANG! A solution is to link all your modules dinamically (option /MD) against CRT. This way they will share the same CRT instance, and you should be able to allocate memory in one module and release it in another. Either that, or make sure that each module cleans its own memory.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.
-
hi, i'm writing a (legacy, non-MFC) dll and there might get an exception thrown in there. it is caught in the exe-file that uses that dll. dll:
//some error throw new CSomeException();
exe:catch (CSomeException *e) { e->SomeFunction(); // works fine delete e; // crash }
the delete-call crashes because the object is not a valid *local* heap-pointer. stepping in dbgheap.c reveales the following passage/* * If this ASSERT fails, a bad pointer has been passed in. It may be * totally bogus, or it may have been allocated from another heap. * The pointer MUST come from the 'local' heap. */ _ASSERTE(_CrtIsValidHeapPointer(pUserData)); // fails
so, finally. how am i supposed to handle this? i mean throwing an exception in a library isn't that uncommon, is it? :confused: :wq -
I bet at least one of your modules (exe or dll) has CRT statically linked. That means that one instance of CRT is allocating the memory and another one tries to release it ... BANG! A solution is to link all your modules dinamically (option /MD) against CRT. This way they will share the same CRT instance, and you should be able to allocate memory in one module and release it in another. Either that, or make sure that each module cleans its own memory.
My programming blahblahblah blog. If you ever find anything useful here, please let me know to remove it.