From b57bf543c7c53e9a41ec3c3441eb34191a7ba37a Mon Sep 17 00:00:00 2001 From: Matteo Cypriani Date: Wed, 24 Aug 2011 11:41:07 +0200 Subject: [PATCH] [Positioning] Fix config parsing memory leaks Do not use exit() from UserInterface::print_information_and_exit_if_requested(), set owl_run to false instead. This function is renamed print_information(). --- owlps-positioning/src/owlps-positioning.cc | 34 ++++++++++++---------- owlps-positioning/src/userinterface.cc | 19 ++++++------ owlps-positioning/src/userinterface.hh | 2 +- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/owlps-positioning/src/owlps-positioning.cc b/owlps-positioning/src/owlps-positioning.cc index 4e12f77..d0807d3 100644 --- a/owlps-positioning/src/owlps-positioning.cc +++ b/owlps-positioning/src/owlps-positioning.cc @@ -14,27 +14,31 @@ using namespace std ; int main(int argc, char **argv) { + owl_run = owl_true ; + /* Read options & configuration */ delete new UserInterface(argc, argv) ; - /* Read input data */ - delete new InputDataReader() ; + if (owl_run) + { + /* Read input data */ + delete new InputDataReader() ; - /* Set up signal handlers */ - struct sigaction action ; - action.sa_flags = 0 ; - sigemptyset(&action.sa_mask) ; - action.sa_handler = owl_sigint_handler ; - sigaction(SIGINT, &action, NULL) ; - action.sa_handler = owl_sigterm_handler ; - sigaction(SIGTERM, &action, NULL) ; + /* Set up signal handlers */ + struct sigaction action ; + action.sa_flags = 0 ; + sigemptyset(&action.sa_mask) ; + action.sa_handler = owl_sigint_handler ; + sigaction(SIGINT, &action, NULL) ; + action.sa_handler = owl_sigterm_handler ; + sigaction(SIGTERM, &action, NULL) ; - /* Run! */ - owl_run = owl_true ; - Positioning positioning ; + /* Run! */ + Positioning positioning ; - /* Clean */ - Stock::clear() ; + /* Clean */ + Stock::clear() ; + } cerr << argv[0] << ": end." << endl ; return 0 ; diff --git a/owlps-positioning/src/userinterface.cc b/owlps-positioning/src/userinterface.cc index ab296b0..04fb535 100644 --- a/owlps-positioning/src/userinterface.cc +++ b/owlps-positioning/src/userinterface.cc @@ -293,7 +293,9 @@ void UserInterface::fill_misc_options() void UserInterface::parse_options() { parse_command_line() ; - print_information_and_exit_if_requested() ; + print_information() ; + if (! owl_run) + return ; parse_file() ; @@ -310,10 +312,12 @@ void UserInterface::parse_command_line() const } -void UserInterface::print_information_and_exit_if_requested() const +/** + * If information is printed, owl_run is set to false, to indicate that + * the program should stop. + */ +void UserInterface::print_information() const { - bool exit_program = false ; - // Print version if requested if (Configuration::is_configured("version")) { @@ -326,18 +330,15 @@ void UserInterface::print_information_and_exit_if_requested() const "unknown version" #endif // OWLPS_VERSION << ".\n" ; - exit_program = true ; + owl_run = owl_false ; // Tell main() to exit } // Print usage if requested if (Configuration::is_configured("help")) { cout << *cli_options ; - exit_program = true ; + owl_run = owl_false ; // Tell main() to exit } - - if (exit_program) - exit(0) ; } diff --git a/owlps-positioning/src/userinterface.hh b/owlps-positioning/src/userinterface.hh index 91c21cd..8a23420 100644 --- a/owlps-positioning/src/userinterface.hh +++ b/owlps-positioning/src/userinterface.hh @@ -37,7 +37,7 @@ protected: void parse_file(void) const ; /// Prints usage and/or version information if requested by the user - void print_information_and_exit_if_requested(void) const ; + void print_information(void) const ; //@} public: