Fix some memory leak bugs.