The problem is the line -
long int tid = strtol(threadID, &threadID, 16); //hex
Which updates the value of threadID
Thus when an attempt to delete
it takes place, it is a bad pointer (ie it is no longer pointing at the right place on the heap).
long int tid = strtol(threadID, NULL, 16); //hex
Fixes the problem. (Thanks to Alberto Massari for the answer).