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