HDFS-16254. Cleanup protobuf on exit of hdfs_allowSnapshot (#3518)

This commit is contained in:
Gautham B A 2021-10-06 21:54:27 +05:30 committed by GitHub
parent a30231ff8e
commit e12cd0c638
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 6 deletions

View File

@ -23,8 +23,6 @@
#include <sstream>
#include <string>
#include <google/protobuf/stubs/common.h>
#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

View File

@ -21,9 +21,22 @@
#include <exception>
#include <iostream>
#include <google/protobuf/stubs/common.h>
#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;
}