If you are free()ing in multiple threads, perhaps a use count and let the last one free() the memory?