Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

RtlValidateHeap Problem

Tags:

c++

dll

I have a Windows DLL that at one point, returns a pointer to a class that is new'ed in the DLL's code. The class itself is a very thin wrapper around another class private to the DLL.

The calling executable has no problem working with this class, everything works fine, with the exception that when the calling executable tries to delete this class, I get a RtlValidateHeap error.

The reasons behind the error makes sense, the exe is trying to free memory on the DLL's heap, which is normally a bad thing.

I've come up with a few possible solutions:

  • Override the class's new operator to allocate its memory off of the executable's heap (provided I can even get at that heap space). The wrapper is very thin, so I would only be allocating a few bytes from the exe's heap.
  • Provide a special destruction function for this class (yuck).
  • Tell the user not to destroy the class and live with leaks (no way!)

Is there a 'normal' way of doing this?

like image 506
Marc Bernier Avatar asked Aug 08 '26 01:08

Marc Bernier


1 Answers

Most libraries that use this sort of functionality, whether C or C++, actually go with your second option - specific functions to get and release objects. It allows distribution of binary DLLs that don't have to be compiled identically to the calling executable.

like image 135
Harper Shelby Avatar answered Aug 10 '26 18:08

Harper Shelby



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!