From 7245fb5f63387b25829b595f5f2917eb6ab64140 Mon Sep 17 00:00:00 2001 From: Zhichao Cao Date: Mon, 21 Oct 2019 15:03:27 -0700 Subject: [PATCH] Fix the potential memory leak of ReplayMultiThread (#5949) Summary: The pointer ra needs to be freed the status s returns not OK. In the previous PR https://github.com/facebook/rocksdb/issues/5934 , the ra is not freed which might cause potential memory leak. Fix this issue by moving the clarification of ra inside the while loop and freeing it as desired. Pull Request resolved: https://github.com/facebook/rocksdb/pull/5949 Test Plan: pass make asan check. Differential Revision: D18045726 Pulled By: zhichao-cao fbshipit-source-id: d5445b7b832c8bb1dafe008bafea7bfe9eb0b1ce --- trace_replay/trace_replay.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/trace_replay/trace_replay.cc b/trace_replay/trace_replay.cc index ef1ae1785..b643e620e 100644 --- a/trace_replay/trace_replay.cc +++ b/trace_replay/trace_replay.cc @@ -313,13 +313,13 @@ Status Replayer::MultiThreadReplay(uint32_t threads_num) { std::chrono::system_clock::now(); WriteOptions woptions; ReadOptions roptions; - ReplayerWorkerArg* ra; uint64_t ops = 0; while (s.ok()) { - ra = new ReplayerWorkerArg; + ReplayerWorkerArg* ra = new ReplayerWorkerArg; ra->db = db_; s = ReadTrace(&(ra->trace_entry)); if (!s.ok()) { + delete ra; break; } ra->woptions = woptions;