It's most likely not a problem with using the "right" or "wrong" malloc function. It sounds more like you're freeing memory outside of where it's being allocated. For example, something gets allocated with the libc malloc() but gets freed with the perl PerlMem_free(). This is an issue for more than just perl extensions... anytime you use a library that might have been linked with a debugging memory allocator you can encounter this.
The rule of thumb is that you free memory in the same module you used to allocate it. That is, if you have a C library which exports a function like:
char* my_crappy_strdup( const char* str ) {
char* s = malloc(strlen(str)+1);
memcpy( s, str, strlen(str)+1 );
return s;
}
Then you also need to provide, in the same source file:
void my_crappy_free( char* str ) {
free(s);
}
And make sure that the caller of my_crappy_strdup() knows that they need to call my_crappy_free() on whatever data is created. Then it doesn't matter if that C library is using perl's memory manager, ElectricFence, libc, or whatever.
One of the interesting consequences of this, by the way, is that it's basically impossible to use libc's strdup() in perl extensions without some nasty #define magic because you'll never be able to get at the libc free() call...
c.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.