title: Can't delete char array using cpp
body: <p>I create a char array in the start of the function, in the wnd I want it to be deleted.</p>
  
  <p>This is my code so far:</p>
  
  <pre><code>void GetPiece(int size)
  {
      //std::cout &lt;&lt; "Downloading File Index: " + currFileIndex &lt;&lt;  " More: " + pieceSize - size;
      char * newBuffer = new char[size];
      bitRequest-&gt;RecvBySize(newBuffer, size - 4, 5);
      newBuffer += 8;
      File file("work_torrent.mp3");
      file.WriteToFile(newBuffer, size - 4);
      file.Close();
  
      pieceSize -= size -4;
      std::cout &lt;&lt; "Downloading File Index: " &lt;&lt; currFileIndex &lt;&lt; " More: " &lt;&lt; pieceSize &lt;&lt; std::endl;
  
      if (pieceSize &lt;= 0)
      {
          currFileIndex++;
          pieceSize = pieces.at(currFileIndex).fileSize;
      }
  
      offset += size - 4;
  
      if (pieceSize &gt; 16384)
      {
          if (1048576 - offset &lt; 16384)
          {
              requestSize = 1048576 - offset;
              if (requestSize == 0)
              {
                  offset = 0;
                  currPieceIndex++;
                  if (pieceSize &gt; 16384)
                  {
                      requestSize = 16384;
                  }
                  else {
                      requestSize = pieceSize;
                  }
              }
          }
          else {
              requestSize = 16384;
          }
  
      }
      else {
          requestSize = pieceSize;
      }
  
  
  
      bitRequest-&gt;RequestPiece(currPieceIndex, offset, requestSize);
  
      delete[] newBuffer; // Try to delete it
  
  
  }
  </code></pre>
  
  <p>When it reaches to the line which delete the char array it gives an error:</p>
  
  <p><a href="https://i.stack.imgur.com/mEXJK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/mEXJK.png" alt="enter image description here"></a></p>
  
  <p>When I am not deleting this char array the code throws a allocation error after some calls to the function.</p>
  
  <p><strong>Edit:</strong></p>
  
  <p>When I didn't increament the newBuffer by 8 the given error is:
  <a href="https://i.stack.imgur.com/QZ5XG.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/QZ5XG.png" alt="enter image description here"></a></p>
  
  <p>Someone know why it's happend?</p>