Fix some memory leak issues