Note that I ended with ptr_remove (npc); in it's removal function, but that will not work. ptr_remove is only removing engine structures, and NPC is a user defined structure. You may have seen that malloc() allocates memory of our structure, free() will remove this memory block again.
So ptr_remove(npc) should have been free(npc);