We don't bite newbies here... much | |
PerlMonks |
[Win32] "Free to wrong pool ..." errorby syphilis (Archbishop) |
on Feb 08, 2009 at 03:25 UTC ( [id://742205]=perlquestion: print w/replies, xml ) | Need Help?? |
syphilis has asked for the wisdom of the Perl Monks concerning the following question:
Hi, This is something that doesn't affect linux, though there could well be other operating systems in addition to Win32 that *are* affected. Let's say I have a static libfoo library that has a my_foo() function that returns a newly allocated (with malloc) string. In C, we can code as follows: No problem with that but, on Win32 perl 5.10 and 5.8, in XS (Inline::C) code that's built against that libfoo library, the same code causes a "Free to wrong pool error..." when the free() call is made. Remove the free() call, and everything is fine - except, of course, that you've then got memory leaks to contend with. How can this be dealt with in XS code ? That is, how can this memory be freed in XS code ? I've written a simple libfoo library that demonstrates the issue (which I can post, if that helps). My simple libfoo library also demonstrates that if the library itself has a function to free the memory, then the problem is solved. That is, if libfoo has a function called foo_free() that looks like this: then, instead of calling free(string) in the XS code, I just call foo_free(string) and everything is fine. But the real life library I'm looking at (libidn) doesn't appear to have such a function (should it ?). That library has a number of functions that return a newly allocated string. For most of those functions, the way that the memory is supposed to be freed is not specified - but where it is specified, the documentation says that the memory should be freed by calling free(), and I surmise that calling free() is the only way that the memory can be freed. As I've outlined above, that works fine for C programs (on both linux and win32), but not for XS code (on win32 only). Cheers, Rob
Back to
Seekers of Perl Wisdom
|
|