Fix a memory leak
If setpriority failed, we wouldn't free this. Just use a unique_ptr to
handle the lifetime for us.
Caught by the static analyzer.
Bug: None
Test: Built. Static analyzer seems happy now.
Change-Id: I10d3e8ff8ba0c10a43d21d9002d73134cef18651
diff --git a/tests/memtest/bandwidth.cpp b/tests/memtest/bandwidth.cpp
index aa02e66..caccd63 100644
--- a/tests/memtest/bandwidth.cpp
+++ b/tests/memtest/bandwidth.cpp
@@ -24,6 +24,7 @@
#include <unistd.h>
#include <map>
+#include <memory>
#include <vector>
@@ -227,7 +228,8 @@
return false;
}
- BandwidthBenchmark *bench = createBandwidthBenchmarkObject(*values);
+ std::unique_ptr<BandwidthBenchmark> bench{
+ createBandwidthBenchmarkObject(*values)};
if (!bench) {
return false;
}
@@ -250,7 +252,6 @@
(*values)["size"].int_value = bench->size();
(*values)["num_warm_loops"].int_value = bench->num_warm_loops();
(*values)["num_loops"].int_value = bench->num_loops();
- delete bench;
return true;
}