Fix global variable leaks