fix memory leaks, added missing variable init values