Re[2]: free the memory allocated in dll, causes Invalid Heap Pointer

Allocating in a Dll and deallocating in a second Dll or exe will fail
if the Dll uses a static C runtime library. You must use a Dll C
runtime to ensure that the same code is doing the allocation and
deallocation if you want to do this type of stuff.

Thanks
That is correct, but what do one need to do that. Any more inputs.

Thanks and Regards
Deepak

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Rajesh Nikam
Sent: Friday, December 03, 2004 5:04 AM
To: Windows System Software Devs Interest List
Subject: Re: [ntdev] free the memory allocated in dll, causes Invalid
Heap Pointer

Hi,

If you are allocating memory in Dll, then provide function in dll to free the memory.
If you are allocating in dll, then do not free memory in application.

-rk

Robert Newton

You need to do the way Rajesh had said else you would be trying to free
memory in another heap which would cause the crash.

Thanks
ntdevstart

“Kotian, Deepak” wrote in message
news:xxxxx@ntdev…
Hi

Please let me know if someone has a solution for this problem:

Application - 32 bit command line executable.
DLL - 32 bit with one function that allocates memory using malloc.

Application and DLL build in debug mode.

Application calls the function, gets the memory block and prints the data.
On trying to free the memory allocated in dll, causes Invalid Heap Pointer
Exception. The reason for the crash is the memory allocated is not in the
local address space of the exe.
If the memory pointer is not accessed, then the free works fine.

Thanks and Regards
Deepak