Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com To: cygwin AT cygwin DOT com Subject: memory allocation within DLLs Message-Id: <20020819211354.D34C23DB1@cavall.jtang.org> Date: Mon, 19 Aug 2002 17:13:54 -0400 (EDT) From: tang AT jtang DOT org (J. Tang) Here's another interesting DLL problem for you all. I have a C file that looks something like this (of course, not checking return values): size = 0xdeadbeef p = malloc (size); lt_dlinit (); handle = lt_dlopen ("some.dll"); f = (function) lt_dlsym (handle, "some_function"); f (&p, &size); /* copy the contents of p into a different location */ /* free (p); CURRENTLY DISABLED*/ lt_dlclose (handle); The DLL was built using Microsoft Visual C++ 6.0 (thanks cgf!). The relevant portion from its source code looks like this: void some_function (char **p, size_t *s) { *p = realloc (*p, *s * 2); /* yes, I know this is bad style */ *s = *s * 2; /* do stuff */ } In other words, the DLL takes a pointer to memory, realloc()s it, then returns it to the caller. With the realloc() call DISABLED within the caller, the program works fine. No errors result at runtime, other than the fact that a memory leak occurs. With the realloc() ENABLED, I get a seg fault on the free() call. So my question is, is memory allocation handled differently on cygwin versus Windows, such that memory allocated by Windows can not be realloc()ed or free()ed by cygwin? Or is it that DLLs have their own memory allocation table separate from the main program, and thus the free() by my cygwin code will fail? (As you can guess, I am not too familiar with Windows DLL internals.) -- Jason Tang / tang AT jtang DOT org / http://www.jtang.org/~tang -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Bug reporting: http://cygwin.com/bugs.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/