From 5051755e35854651725d72844b003f6c24e74b60 Mon Sep 17 00:00:00 2001 From: Islam AbdelRahman Date: Fri, 2 Sep 2016 10:58:08 -0700 Subject: [PATCH] Fix db_bench memory use after free (detected by clang_analyze) Summary: Fix using `arg[i].thread` after deleting it Test Plan: run clang_analyze Subscribers: andrewkr, dhruba Differential Revision: https://reviews.facebook.net/D63171 --- tools/db_bench_tool.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tools/db_bench_tool.cc b/tools/db_bench_tool.cc index 4db545757..a3e1fd0f8 100644 --- a/tools/db_bench_tool.cc +++ b/tools/db_bench_tool.cc @@ -2460,11 +2460,6 @@ class Benchmark { } shared.mu.Unlock(); - for (int i = 0; i < n; i++) { - delete arg[i].thread; - } - delete[] arg; - // Stats for some threads can be excluded. Stats merge_stats; for (int i = 0; i < n; i++) { @@ -2472,6 +2467,11 @@ class Benchmark { } merge_stats.Report(name); + for (int i = 0; i < n; i++) { + delete arg[i].thread; + } + delete[] arg; + return merge_stats; }