From e12cd0c6388550bc71b714bf937186a0346ff54c Mon Sep 17 00:00:00 2001 From: Gautham B A Date: Wed, 6 Oct 2021 21:54:27 +0530 Subject: [PATCH] HDFS-16254. Cleanup protobuf on exit of hdfs_allowSnapshot (#3518) --- .../hdfs-allow-snapshot/hdfs-allow-snapshot.cc | 5 ----- .../libhdfspp/tools/hdfs-allow-snapshot/main.cc | 15 ++++++++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-allow-snapshot/hdfs-allow-snapshot.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-allow-snapshot/hdfs-allow-snapshot.cc index 991c39b98a..f30e8c71d6 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-allow-snapshot/hdfs-allow-snapshot.cc +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-allow-snapshot/hdfs-allow-snapshot.cc @@ -23,8 +23,6 @@ #include #include -#include - #include "hdfs-allow-snapshot.h" #include "tools_common.h" @@ -112,9 +110,6 @@ bool AllowSnapshot::HandlePath(const std::string &path) const { std::cerr << "Error: " << status.ToString() << std::endl; return false; } - - // Clean up static data and prevent valgrind memory leaks - google::protobuf::ShutdownProtobufLibrary(); return true; } } // namespace hdfs::tools \ No newline at end of file diff --git a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-allow-snapshot/main.cc b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-allow-snapshot/main.cc index e24fc7db13..086d376a8f 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-allow-snapshot/main.cc +++ b/hadoop-hdfs-project/hadoop-hdfs-native-client/src/main/native/libhdfspp/tools/hdfs-allow-snapshot/main.cc @@ -21,9 +21,22 @@ #include #include +#include + #include "hdfs-allow-snapshot.h" int main(int argc, char *argv[]) { + const auto result = std::atexit([]() -> void { + // Clean up static data on exit and prevent valgrind memory leaks + google::protobuf::ShutdownProtobufLibrary(); + }); + if (result != 0) { + std::cerr << "Error: Unable to schedule clean-up tasks for HDFS allow " + "snapshot tool, exiting" + << std::endl; + std::exit(EXIT_FAILURE); + } + hdfs::tools::AllowSnapshot allow_snapshot(argc, argv); auto success = false; @@ -35,7 +48,7 @@ int main(int argc, char *argv[]) { } if (!success) { - exit(EXIT_FAILURE); + std::exit(EXIT_FAILURE); } return 0; } \ No newline at end of file