Hello monks,

I've run into a bug that I'm having a very difficult time locating that I'm hoping you can provide some guidance on.

I have a test that is producing the following error:

*** glibc detected *** perl: corrupted double-linked list
I suspect an XS module I'm using is doing something bad. I've done a fair bit of research into this and tried these approaches at isolating the bug:

1) set the MALLOC_CHECK_ environment variable. There was some success here as the error changed to this:

*** glibc detected *** perl: realloc(): invalid pointer
2) I tried to run this under gdb to hopefully get a stack trace so I can find the offending function. I have done this in the past to debug seg faults successfully:
> gdb perl (gdb) set args <args> (gdb) run
This time I got no additional information. The invalid pointer error is still thrown (assuming MALLOC_CHECK_ is set, otherwise it's the linked list error) with no additional stack trace information. I'm assuming this is due to a lack of debugging symbols.

3) I have tried to run this under valgrind. Initially, I got a valgrind error that VG_N_SEGMENTS was too low. I recompiled valgrind with a higher limit here. The code now passes entirely every time I run it under valgrind.

So I seem to have no additional useful information from my limited C debugging skill set.

Can any kind monk offer some guidance on what next steps I might take to debug this issue? I would offer code but it's far too complex without being able to localize the issue, so I apologize on that front.

Thanks in advance for your time, it's much appreciated :)

EDIT: I suppose some version information would be good. This is red hat enterprise linux 10 and perl 5.12.2. I can give any other information that would be useful.

EDIT2: Make that SUSE Linux Enterprise Server 10 (x86_64). Not sure where I got red hat from as the last time I did anything with that was years ago in school.

############################################################################

I managed to resolve the issue and wanted I'd post the details here just in case it may be useful to someone else.

As it turned out, the problem was my assumption that an XS module was at fault. I was basing this on the error and that the problem was occurring pretty close to some of my own XS code. Turns out the problem was a simple perl side issue.

The clue that I missed was that the code was taking significantly longer to execute than it should have and that I was getting some output that mentioned a memory wrap after the error from above.

The real issue was a bad (very large) loop variable outside the XS code that was causing the process to allocate all its memory, resulting in perl throwing the memory error above.

I am unclear on why the code would complete under valgrind. I do know that once I realized the issue and started watching memory, the process was consuming upwards of 50G of memory. I am also unclear why I didn't get any point of failure information from gdb...although once you're out of memory I suppose all bets are off.

Thanks to all for the great insights, especially the information about MALLOC_CHECK_ values and the valgrind options. I appreciate it!


In reply to (resolved) *** glibc detected *** perl: corrupted double-linked list by tj_thompson

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.