memory: fix memory leaks scattered around