Note that there are some explanatory texts on larger screens.

plurals
  1. POMystery heap corruption, why?
    text
    copied!<p>I've had a bug in my code for some time that I can't figure out. Maybe I'm just blind, but this bug doesn't make much sense, because from what I can see, this code is flawless. I speculate that there may be corruption from somewhere else, but I figured I'd paste my problem code here just in case.</p> <p>I know there is heap corruption because I get the standard <strong>Error</strong> message followed by a free() invalid next size message. I've included what I feel to be relevant. Heap corruption occurs on the second free(FileBuf);</p> <pre><code>while ((DirPtr = readdir(ProcDir))) { if (AllNumeric(DirPtr-&gt;d_name) &amp;&amp; atoi(DirPtr-&gt;d_name) &gt;= InObj-&gt;ObjectPID &amp;&amp; atoi(DirPtr-&gt;d_name) &lt;= InObj-&gt;ObjectPID + 10) /*Search 10 PIDs forward.*/ { char TChar; snprintf(FileName, sizeof FileName, "/proc/%s/cmdline", DirPtr-&gt;d_name); if (!(Descriptor = fopen(FileName, "r"))) { closedir(ProcDir); return 0; } FileBuf = malloc(MAX_LINE_SIZE); /*Scroll further down to find the free()s.*/ for (Inc = 0; (TChar = getc(Descriptor)) != EOF &amp;&amp; Inc &lt; MAX_LINE_SIZE - 1; ++Inc) { FileBuf[Inc] = TChar; } FileBuf[Inc] = '\0'; fclose(Descriptor); for (Inc = 0, Inc2 = NumSpaces; Inc2 != 0; ++Inc) { /*We need to replace the NUL characters with spaces.*/ if (FileBuf[Inc] == '\0') { --Inc2; FileBuf[Inc] = ' '; } } if (!strcmp(FileBuf, InObj-&gt;ObjectStartCommand)) { unsigned long RealPID; free(FileBuf); FileBuf = NULL; snprintf(FileName, sizeof FileName, "%s", DirPtr-&gt;d_name); closedir(ProcDir); RealPID = atoi(FileName); if (UpdatePID) { InObj-&gt;ObjectPID = RealPID; } return RealPID; } /*And here is the problem.*/ free(FileBuf); } } closedir(ProcDir); return 0; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload