title: What causes double free or corruption (out) error?
body: <p><strong>Possible Duplicate:</strong>
  <a href="https://stackoverflow.com/questions/26739265/opencv-double-free-or-corruption-out-aborted-core-dumped">OpenCV double free or corruption (out): Aborted (core dumped)</a></p>
  
  <p>I created a function that will receive image from client and use OpenCV in server to process image and return data.
  I have realized that I get this error only when I use function <em>free()</em>. Below is the code in my function.</p>
  
  <pre><code>// 2. Create Mat Image
  Mat image = Mat::zeros(height, width, CV_8UC3);
  uchar sockData[imageSize];
  
  //Receive Image data here
  printf("Receiving Image Data\n");
  for (int i = 0; i &lt; imageSize; i += bytecount)
  {
     if ((bytecount = recv(*csock, sockData +i, imageSize - i, 0)) == -1)
     {
        fprintf(stderr, "Error receiving image %d\n", errno);
     }
  }
  // deallocate 
  deallocateMemory(csock);
  
  // Image Data Received, Now Reconstructing Image
  printf("Image Data Received, Now Reconstructing\n");
  int ptr = 0;
  for (int i = 0; i &lt; image.rows; i++)
  {
    for (int j = 0; j &lt; image.cols; j++)
    {
        image.at&lt;cv::Vec3b&gt;(i,j) = cv::Vec3b(sockData[ptr+0],sockData[ptr+1],
        sockData[ptr+2]);ptr = ptr + 3;
     }
  }
  // Write produced output to stdout - Print
  printf("Image Processed, now Displaying Results...\n");
  displayResultsOnConsole(results);
  
  // free(sockData);
  return 0;
  </code></pre>
  
  <p>The error appears when I uncomment <code>free(sockData);</code>
  Am I doing anything wrong?</p>