 <p>Without knowing exactly how this should work I can say that you write outside of the <code>p</code> vector on </p> <pre><code> for (i=0; i &lt; rptr-&gt;n; i++) { lptr-&gt;keys[lptr-&gt;n + 1 + i] = rptr-&gt;keys[i]; // When you delete key 84, rptr-&gt;n is 4 at one point which takes you outside // p[M] lptr-&gt;p[lptr-&gt;n + 2 + i] = rptr-&gt;p[i+1]; } </code></pre> <p>Valgrind is a good tool to use, and I found this problem by <code>valgrind -v --leak-check=full &lt;your executable&gt;</code></p>