I have a Windows DLL, which at some point returns a pointer to a class that was new'ed in the DLL code. The class itself is a very thin shell around another class private to the DLL.
The calling executable works without problems with this class, everything works fine, except that when the calling executable tries to delete this class, I get an RtlValidateHeap error.
The causes of the error make sense; exe is trying to free memory on the DLL heap, which is usually bad.
I came up with several possible solutions:
- redefine the operator of the new class to allocate its memory from the executable heap (provided that I can even get into this heap space). The wrapper is very thin, so I would extract a few bytes from the exe heap.
- Provide a special destruction function for this class (yuck).
- Tell the user not to destroy the class and live with leaks (in no way!)
Is there a “normal” way to do this?
source
share