[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: _CrtIsValidHeapPointer Problem
- From: "jason zhang" <jzhang@...>
- Date: Fri, 25 Aug 2006 18:03:32 +0800
Thanks all of you.
I suspend this problem for about one week and look at it again today.
I compared the DLL case and exe case. The same C code works well
in a exe but cause a heap error in dll. Below is what I get during debuging:
When create a array in a DLL, it will allocate some memory and they are
stored in the stack of the interpreter. When the script finished, the interpreter
will call lua_close(L) to release the resources. But I found that, it unload the
dll before clear the stack, so, the memory allocated in the DLL is invalid.
For Lua 5.1
lstate.c, line 210, in the function LUA_API void lua_close (lua_State *L)
do { /* repeat until no more errors */
L->ci = L->base_ci;
L->base = L->top = L->ci->base;
L->nCcalls = 0;
} while (luaD_rawrunprotected(L, callallgcTM, NULL) != 0); // Line 210
Inside the luaD_rawrunprotected function, it will call luaC_callGCTM() function to clear all the user data,
Finally, the routine go to the static int gctm (lua_State *L) function in loadlib.c, which
unload the dll from the interpreter. So , all the memory allocated in DLL is invalid.
Is my analysis correct?
What I can't understand is, why only the array cause the problem, while normal table works.
And I also don't understand why it works if I insert an element with index zero.
Please help me.
Thank you so much.
----- Original Message -----
From: "Jerome Vuarand" <jerome.vuarand@ubisoft.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Friday, August 18, 2006 10:19 PM
Subject: RE: _CrtIsValidHeapPointer Problem
> I have used the multithreaded DLL for the DLL and multithreaded for the
> interpreter, but the error is still there.
You should use "Multithreaded DLL" for the DLL, but also "Multithreaded DLL" for the interpreter. The "DLL" word here don't represent the type of project, but the place where the CRT is (either in msvcrt.lib or in msvcrt.dll). All dlls *AND* the exe loading them must use the same version of the msvcrt.
And to explain the difference when you insert at table index 0, it's probably because _CrtIsValidHeapPointer is not a 100% sure detection method and the difference in memory allocations hides the memory corruption problem.
-----Message d'origine-----
De : lua-bounces@bazar2.conectiva.com.br [mailto:lua-bounces@bazar2.conectiva.com.br] De la part de jason zhang
Envoyé : 16 août 2006 23:44
À : Lua list
Objet : Re: _CrtIsValidHeapPointer Problem
I have used the multithreaded DLL for the DLL and multithreaded for the interpreter, but the error is still there.
ps. The static lua library is linked into the extension DLL, is that incorrect?
what's more, why it works well when I insert a element with index zero?
Thank you.
Regards,
Jason
----- Original Message -----
From: "D Burgess" <dburgess@gmail.com>
To: "Lua list" <lua@bazar2.conectiva.com.br>
Sent: Thursday, August 17, 2006 11:31 AM
Subject: Re: _CrtIsValidHeapPointer Problem
> You should use multithreaded DLL. (/MD)You cannot have a static
> Lua Library and an extension DLL
>
> David B
>
> jason zhang wrote:
>> 2. Different Crt library
>> I double checked this. The crt of Lua Interpreter, Lua static Library and the extension DLL are
>> the same. In VC6.0, I set all of them to Debug Single-Threaded. Should I use mutli-Threaded Crt?
>