From: Michal MalĂ˝ Date: Wed, 9 Jul 2014 10:14:35 +0000 (+0200) Subject: Rework error handling in main() X-Git-Url: https://gitweb.devoid-pointer.net/?a=commitdiff_plain;h=e146880f9183e69936402a699c082721257ec10b;p=LFSBench.git Rework error handling in main() --- diff --git a/main.c b/main.c index 5738a61..9e0b979 100644 --- a/main.c +++ b/main.c @@ -70,7 +70,7 @@ int main(int argc, char** argv) ret = asprintf(&evdev_path, "%s", argv[1]); if (ret < 0) { fprintf(stderr, "CRTITICAL: Cannot set up event device path\n"); - return -1; + goto bail_out_1; } /* Setup threading data */ @@ -78,37 +78,36 @@ int main(int argc, char** argv) exit_app = 0; if (pthread_mutex_init(&exit_mutex, NULL) != 0) { fprintf(stderr, "CRITICAL: Cannot create exit_mutex!"); - return -1; + goto bail_out_1; } - + etd.exit_mutex = &exit_mutex; etd.pexit_app = &exit_app; - + if (XInitThreads() <= 0) { fprintf(stderr, "Unable to initialize X11 threads\n"); - pthread_mutex_destroy(&exit_mutex); - return -1; + goto bail_out_2; } /* Create main window */ if (create_window() < 0) - return -1; + goto bail_out_2; /* Start main window event loop */ if (pthread_create(&win_event_loop, NULL, &window_event_loop, &etd) != 0) { fprintf(stderr, "CRITICAL: Cannot start main window event loop!\n"); - return -1; + goto bail_out_2; } - + if (init_keyb_logging(evdev_path) != 0) - goto exit; - + goto bail_out_3; + if (init_fps_counter(&etd) != 0) - goto exit; - + goto bail_out_3; + if (pthread_create(&kb_event_loop, NULL, &get_keyb_events, &etd) != 0) { fprintf(stderr, "CRITICAL: Cannot start boundkeys event loop!\n"); - return -1; + goto bail_out_3; } - + pthread_join(win_event_loop, NULL); stop_benchmark(); destroy_window(); @@ -117,11 +116,14 @@ int main(int argc, char** argv) pthread_mutex_destroy(&exit_mutex); + free(evdev_path); return 0; - - exit: - pthread_join(win_event_loop, NULL); + +bail_out_3: + pthread_join(win_event_loop, NULL); +bail_out_2: pthread_mutex_destroy(&exit_mutex); - +bail_out_1: + free(evdev_path); return -1; }