<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" 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': corrupted size vs. prev_size:</span> Can'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's the code below:</p>
<p style="margin-top:0;margin-bottom:0"></p>
<div>pfilenames = malloc((numfiles &#43; 1) * sizeof(char*));<br>
&nbsp;&nbsp; if(pfilenames == NULL)<br>
&nbsp;&nbsp; {<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; perror(&quot;malloc failed\n&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exit(EXIT_FAILURE);<br>
&nbsp;&nbsp; }<br>
<br>
pfilenames[i] = malloc( (strlen(direntptr-&gt;d_name) &#43; 1) * sizeof(char));<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;if(pfilenames[i] == NULL)<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;{<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; perror(&quot;malloc failed\n&quot;);<br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;exit(EXIT_FAILURE);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;}<br>
&nbsp;&nbsp;&nbsp; &nbsp;<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;strcpy(pfilenames[i], direntptr-&gt;d_name);<br>
&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;i&#43;&#43;;</div>
&nbsp;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>
<p style="margin-top:0;margin-bottom:0">Marlon<br>
</p>
</div>
</body>
</html>