justin_skariah has asked for the wisdom of the Perl Monks concerning the following question:

Hi All,

I am using swig so that i can call my so library from perl. But when perl exits i am getting the following error.

==644== Warning: bad signal number 0 in sigaction() ==644== Invalid free() / delete / delete[] ==644== at 0x40057F6: free (vg_replace_malloc.c:325) ==644== by 0x8072E7F: perl_destruct (in /opt/perl/bin/perl-static) ==644== by 0x8060D6F: main (in /opt/perl/bin/perl-static) ==644== Address 0xab79180 is 0 bytes inside data symbol "buffer.17598 +"
the symbol buffer.17598 is present in on of the so file i am loading. but no reference is passed in or out of c. But still some how perl is getting this reference and trying to free it. How can i stop perl from doing this?

Replies are listed 'Best First'.
Re: perl_destruct clearing memory allocated in c library
by ikegami (Patriarch) on Mar 23, 2011 at 16:43 UTC

    Do you call malloc or free in a file that does #include perl.h? Perl redefines them.

    Do you set the PV of a SV to the buffer? Then set the LEN to 0 to prevent Perl from freeing it.

      Actually the symbol buffer.17598 which valgrind says is causing the problem is been found in one 'so' file I use. I greped all the so files. And I doubt that 'so' file is using perl.h. I don't have source code for that 'so'.

      Sorry but I couldn't understand what PV and SV means.

        I was asking if you were passing it to Perl. But I guess you already answered that ("but no reference is passed in or out of c.").