remove global leaks

gleaks found some global variable leaks while I was executing some tests, the fixes are attached.