fix some memory leak issues