8000 don't leak on help · saliormoon/arangodb@89ac2df · GitHub
[go: up one dir, main page]

Skip to content

Commit 89ac2df

Browse files
committed
don't leak on help
1 parent 41832d6 commit 89ac2df

File tree

9 files changed

+45
-6
lines changed

9 files changed

+45
-6
lines changed

arangod/RestServer/arangod.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,10 @@ static int runServer(int argc, char** argv) {
164164

165165
try {
166166
server.run(argc, argv);
167+
if (server.helpShown()) {
168+
// --help was displayed
169+
ret = EXIT_SUCCESS;
170+
}
167171
} catch (std::exception const& ex) {
168172
LOG(ERR) << "arangod terminated because of an unhandled exception: "
169173
<< ex.what();

arangosh/Benchmark/arangobench.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ int main(int argc, char* argv[]) {
6464

6565
try {
6666
server.run(argc, argv);
67+
if (server.helpShown()) {
68+
// --help was displayed
69+
ret = EXIT_SUCCESS;
70+
}
6771
} catch (std::exception const& ex) {
6872
LOG(ERR) << "arangobench terminated because of an unhandled exception: "
6973
<< ex.what();

arangosh/Dump/arangodump.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ int main(int argc, char* argv[]) {
6060

6161
try {
6262
server.run(argc, argv);
63+
if (server.helpShown()) {
64+
// --help was displayed
65+
ret = EXIT_SUCCESS;
66+
}
6367
} catch (std::exception const& ex) {
6468
LOG(ERR) << "arangodump terminated because of an unhandled exception: "
6569
<< ex.what();

arangosh/Import/arangoimp.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ int main(int argc, char* argv[]) {
6262

6363
try {
6464
server.run(argc, argv);
65+
if (server.helpShown()) {
66+
// --help was displayed
67+
ret = EXIT_SUCCESS;
68+
}
6569
} catch (std::exception const& ex) {
6670
LOG(ERR) << "arangoimp terminated because of an unhandled exception: "
6771
<< ex.what();

arangosh/Restore/arangorestore.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ int main(int argc, char* argv[]) {
6262

6363
try {
6464
server.run(argc, argv);
65+
if (server.helpShown()) {
66+
// --help was displayed
67+
ret = EXIT_SUCCESS;
68+
}
6569
} catch (std::exception const& ex) {
6670
LOG(ERR) << "arangorestore terminated because of an unhandled exception: "
6771
<< ex.what();

arangosh/Shell/arangosh.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ int main(int argc, char* argv[]) {
7272

7373
try {
7474
server.run(argc, argv);
75+
if (server.helpShown()) {
76+
// --help was displayed
77+
ret = EXIT_SUCCESS;
78+
}
7579
} catch (std::exception const& ex) {
7680
LOG(ERR) << "arangosh terminated because of an unhandled exception: "
7781
<< ex.what();

arangosh/VPack/arangovpack.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,10 @@ int main(int argc, char* argv[]) {
5656

5757
try {
5858
server.run(argc, argv);
59+
if (server.helpShown()) {
60+
// --help was displayed
61+
ret = EXIT_SUCCESS;
62+
}
5963
} catch (std::exception const& ex) {
6064
LOG(ERR) << "arangovpack terminated because of an unhandled exception: "
6165
<< ex.what();

lib/ApplicationFeatures/ApplicationServer.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,11 @@ void ApplicationServer::run(int argc, char* argv[]) {
166166
// file(s)
167167
parseOptions(argc, argv);
168168

169+
if (!_helpSection.empty()) {
170+
// help shown. we can exit early
171+
return;
172+
}
173+
169174
// seal the options
170175
_options->seal();
171176

@@ -285,17 +290,17 @@ void ApplicationServer::collectOptions() {
285290
void ApplicationServer::parseOptions(int argc, char* argv[]) {
286291
ArgumentParser parser(_options.get());
287292

288-
std::string helpSection = parser.helpSection(argc, argv);
293+
_helpSection = parser.helpSection(argc, argv);
289294

290-
if (!helpSection.empty()) {
295+
if (!_helpSection.empty()) {
291296
// user asked for "--help"
292297

293298
// translate "all" to "*"
294-
if (helpSection == "all") {
295-
helpSection = "*";
299+
if (_helpSection == "all") {
300+
_helpSection = "*";
296301
}
297-
_options->printHelp(helpSection);
298-
exit(EXIT_SUCCESS);
302+
_options->printHelp(_helpSection);
303+
return;
299304
}
300305

301306
if (!parser.parse(argc, argv)) {

lib/ApplicationFeatures/ApplicationServer.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -166,6 +166,9 @@ class ApplicationServer {
166166

167167
~ApplicationServer();
168168

169+
std::string helpSection() const { return _helpSection; }
170+
bool helpShown() const { return !_helpSection.empty(); }
171+
169172
// adds a feature to the application server. the application server
170173
// will take ownership of the feature object and destroy it in its
171174
// destructor
@@ -297,6 +300,9 @@ class ApplicationServer {
297300

298301
// reporter for progress
299302
std::vector<ProgressHandler> _progressReports;
303+
304+
// help section displayed
305+
std::string _helpSection;
300306
};
301307
}
302308
}

0 commit comments

Comments
 (0)
0