title: Understanding 'double free or corruption' error
body: <p>I am calling a <code>C++</code> application from the <code>python</code> script (OS Ubuntu 14.04) like this:</p>
  
  <pre><code>import sys, subprocess
  run = subprocess.Popen(['app'] + args, stdout = subprocess.PIPE,
                         stderr = subprocess.PIPE)
  stdout, stderr = run.communicate()
  if stderr:
      sys.stderr.write('Error in app: ' + stderr.decode('utf-8'))
      sys.exit(1)
  </code></pre>
  
  <p>Then I get the following error message (although the address is different every time):</p>
  
  <pre><code>*** Error in `/usr/bin/app': double free or corruption (!prev): 0x00007f50eae98070 ***
  </code></pre>
  
  <p>The app itself is a third-party binary, that means, I have no access to the source code. However, even under suggestion that there is some bug in <code>app</code> that causes deletion attempt the same entity twice there are 3 strangenesses in the behaviour that I cannot understand:</p>
  
  <ol>
  <li>The error occurs randomly and rather rare (around 20% of all runs on the very same data). Some other users of the <code>app</code> get this error as well; however, some of them never get it.</li>
  <li>It does not get caught in the <code>stderr</code> stream of the subprocess (and therefore <code>sys.exit(1)</code> does not get executed).</li>
  <li>Sometimes I see <code>top</code> instead of <code>!prev</code> in the brackets.</li>
  </ol>
  
  <p>Can someone explain me, how these features can be originated or even give an example C++ code that reproduces this behaviour?</p>