False Memory Leak Detected in DLL

Started by
2 comments, last by FMDGames 17 years, 11 months ago
Situation: I am trying to develop code that is modular in the form of a DLL. The host program calling the DLL file executes a function called Register() which contains lua_registers() for all functions within the DLL that are to be accessable by lua. This all works fine. Problem: During cleanup, when lua_close(luaVM); is called, the following is displayed in a dialog box: ------------------------------------------------------------------------------- Windows has triggered a breakpoint in project.exe. This may be due to a corruption of the heap, and indicates a bug in project.exe or any of the DLLs it has loaded. The output window may have more diagnostic information |BREAK| |CONTINUE| |IGNORE| ------------------------------------------------------------------------------- Pressing BREAK takes me into dbgheap.c to _CrtIsValidHeapPointer. If you look at the description, it says the following: *int _CrtIsValidHeapPointer() - verify pointer is from 'local' heap * *Purpose: * Verify pointer is not only a valid pointer but also that it is from * the 'local' heap. Pointers from another copy of the C runtime (even in the * same process) will be caught. * *Entry: * const void * pUserData - pointer of interest * *Return: * TRUE - if valid and from local heap * FALSE otherwise But as the pointers that are used for lua come from the DLL, that means its NOT on the local heap, but instead the heap used for the DLL. Sorry for the long post, i've been hammering away at this for too long now. Thanks for any suggestions :)
Advertisement
My guess would be that there is some other cleanup that needs to be performed that isn't being performed.
"I thought what I'd do was, I'd pretend I was one of those deaf-mutes." - the Laughing Man
When working with DLLs, it is absolutely imperative that memory is freed by the same module that allocated. If you new it in the DLL, you have to delete it in the DLL.
The problem is that I don't create the pointer, the pointer is created by lua internally when lua_register() is called. Once lua_register() is called, then you can call the function from lua using the name you designated:

lua_register(luaVM, "mytestfunction", lfn_MyTestFunction);

so in C the function is called lfn_MyTestFunction where in lua, you use mytestfunction() to call the C function.

So basically, Will I need to deallocate that pointer by inserting a function in lua's C source code?

This topic is closed to new replies.

Advertisement