Probably fixed invalid pointer bug, with no leaks