From 47d280d3b0f3e271d29ffcffa061b5ad54f08b7e Mon Sep 17 00:00:00 2001 From: joshualitt Date: Thu, 16 Jul 2015 14:23:22 -0700 Subject: [PATCH] Fix visual bench memory leak BUG=skia: Review URL: https://codereview.chromium.org/1239103002 --- tools/VisualBench/VisualBench.cpp | 7 ++----- tools/VisualBench/VisualBench.h | 2 +- tools/VisualBench/VisualBenchmarkStream.cpp | 5 ++++- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/tools/VisualBench/VisualBench.cpp b/tools/VisualBench/VisualBench.cpp index e97db8a308..d8713e743c 100644 --- a/tools/VisualBench/VisualBench.cpp +++ b/tools/VisualBench/VisualBench.cpp @@ -163,10 +163,7 @@ bool VisualBench::advanceRecordIfNecessary(SkCanvas* canvas) { return true; } - while ((fBenchmark = fBenchmarkStream->next()) && - (SkCommandLineFlags::ShouldSkip(FLAGS_match, fBenchmark->getUniqueName()) || - !fBenchmark->isSuitableFor(Benchmark::kGPU_Backend))) {} - + fBenchmark.reset(fBenchmarkStream->next()); if (!fBenchmark) { return false; } @@ -238,7 +235,7 @@ void VisualBench::draw(SkCanvas* canvas) { fState = kPreWarmLoops_State; this->printStats(); fBenchmark->perCanvasPostDraw(canvas); - fBenchmark = NULL; + fBenchmark.reset(NULL); fCurrentSample = 0; fFlushes = 1; fLoops = 1; diff --git a/tools/VisualBench/VisualBench.h b/tools/VisualBench/VisualBench.h index 683151f566..b8cd2bdb77 100644 --- a/tools/VisualBench/VisualBench.h +++ b/tools/VisualBench/VisualBench.h @@ -68,7 +68,7 @@ private: WallTimer fTimer; State fState; SkAutoTDelete fBenchmarkStream; - Benchmark* fBenchmark; + SkAutoTUnref fBenchmark; // support framework SkAutoTUnref fSurface; diff --git a/tools/VisualBench/VisualBenchmarkStream.cpp b/tools/VisualBench/VisualBenchmarkStream.cpp index 1f16664081..e3eb44d5b9 100644 --- a/tools/VisualBench/VisualBenchmarkStream.cpp +++ b/tools/VisualBench/VisualBenchmarkStream.cpp @@ -68,7 +68,9 @@ Benchmark* VisualBenchmarkStream::next() { Benchmark* bench; // skips non matching benches while ((bench = this->innerNext()) && - SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName())) { + (SkCommandLineFlags::ShouldSkip(FLAGS_match, bench->getUniqueName()) || + !bench->isSuitableFor(Benchmark::kGPU_Backend))) { + bench->unref(); } return bench; } @@ -82,6 +84,7 @@ Benchmark* VisualBenchmarkStream::innerNext() { fBenchType = "micro"; return bench; } + bench->unref(); } while (fGMs) {