HDFS-16254. Cleanup protobuf on exit of hdfs_allowSnapshot (#3518)
This commit is contained in:
parent
a30231ff8e
commit
e12cd0c638
@ -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
|
@ -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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user