I still don't have a solid understanding of where the root of the problem even lies.

The worst part about "heap corruption" is that a) it can be caused by anything that can write to memory; b) can not be discovered until long after it happens.

A strcpy from a string with a missing null will write on for a long time and usually corrupt so much that it fails quickly.

But a write of an integer through a miscalculated pointer will only affect 4 or 8 bytes and won't be discovered until the program tries to make use of the value that should be there. If the data that gets overwritten happens to be a heap internal value -- say a sentinel or offset -- then the corruption may not be discovered until much later; often not until global cleanup as the program terminates.

The only way I know of to debug heaps -- and I only tried it once -- is to recompile the program (perl.exe in this case) with CRT Debug Heap configured. That will (theoretically) discover the corruption much earlier and get you closer to the errant code. The big problem is then translating the machine address from which the write occurred into something that you can relate to your Perl code.

And, it is not unheard of that configuring the debug heap makes the problem "go away". Of course, it doesn't really. It just causes the errant write to hit something that doesn't hurt -- a piece of freed, never reused memory or similar -- until you remove all the extra space used by the debug routines; and then it just comes back again.

I feel for your irritation at not knowing; but sometimes you just have to know when to let stuff go :)


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
In the absence of evidence, opinion is indistinguishable from prejudice.

In reply to Re^6: Hard to Debug windows memory error by BrowserUk
in thread Hard to Debug windows memory error by jandrew

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.