Fix memory leak/uninitialized var