OSDN Git Service

Perfprofd: Add ScopeGuard for file deletion
authorAndreas Gampe <agampe@google.com>
Thu, 26 Apr 2018 05:32:36 +0000 (22:32 -0700)
committerAndreas Gampe <agampe@google.com>
Thu, 3 May 2018 20:33:17 +0000 (13:33 -0700)
Ensure that the temporary will be deleted.

(cherry picked from commit 529af96ba77f26c1597d077ca55d051feeb5df3d)

Bug: 73175642
Test: perfprofd_test
Merged-In: I4e15cd4fa81a173a70126edaea5c0a0023b8c359
Change-Id: I4e15cd4fa81a173a70126edaea5c0a0023b8c359

perfprofd/perfprofdcore.cc

index 065f8e6..c5605ac 100644 (file)
@@ -36,6 +36,7 @@
 #include <android-base/file.h>
 #include <android-base/logging.h>
 #include <android-base/macros.h>
+#include <android-base/scopeguard.h>
 #include <android-base/stringprintf.h>
 
 #ifdef __BIONIC__
@@ -650,6 +651,9 @@ static ProtoUniquePtr collect_profile(Config& config)
   bool take_action = (hardwire && duration <= max_duration);
   HardwireCpuHelper helper(take_action);
 
+  auto scope_guard = android::base::make_scope_guard(
+      [&data_file_path]() { unlink(data_file_path.c_str()); });
+
   //
   // Invoke perf
   //