<div dir="ltr"><div>This is due to some invalid memory writes to the heap.<br></div><div><br></div><div>~ Ben<br></div><div><br></div><div><div class="gmail_extra"><div class="gmail_quote">On Wed, Oct 3, 2018 at 6:56 AM, Marlon Seaton <span dir="ltr">&lt;<a href="mailto:mseaton@stevens.edu" target="_blank">mseaton@stevens.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div dir="ltr">
<div id="m_-6868886503494923517m_-3302431062160527874divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif" dir="ltr">
<p style="margin-top:0;margin-bottom:0">Good morning,</p>
<p style="margin-top:0;margin-bottom:0">I am have the following memory error: <span>
Error in `./ls&#39;: corrupted size vs. prev_size:</span> Can&#39;t seem to figure out why, but I believe it may have to do with how I am trying to allocate an array of pointers to strings. I guess my question is could the following code snippet potentially cause the
 problem that I am having?</p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Here&#39;s the code below:</p>
<p style="margin-top:0;margin-bottom:0"></p>
<div>pfilenames = malloc((numfiles + 1) * sizeof(char*));<br>
   if(pfilenames == NULL)<br>
   {<br>
       perror(&quot;malloc failed\n&quot;);<br>
       exit(EXIT_FAILURE);<br>
   }<br>
<br>
pfilenames[i] = malloc( (strlen(direntptr-&gt;d_name) + 1) * sizeof(char));<br>
         if(pfilenames[i] == NULL)<br>
         {<br>
              perror(&quot;malloc failed\n&quot;);<br>
               exit(EXIT_FAILURE);<br>
         }<br>
     <br>
         strcpy(pfilenames[i], direntptr-&gt;d_name);<br>
         i++;</div>
 numfiles is the number of files in the directory. I keep a running total of this as I am reading the files in the directory.
<p></p>
<p style="margin-top:0;margin-bottom:0"><br>
</p>
<p style="margin-top:0;margin-bottom:0">Thank you.</p><span class="m_-6868886503494923517HOEnZb"><font color="#888888">
<p style="margin-top:0;margin-bottom:0">Marlon<br>
</p>
</font></span></div>
</div>

</blockquote></div><br></div></div></div>