Update debug.h

old implementation leaked memory