]> Devoid-pointer.net GitWeb - LFSBench.git/commitdiff
Rework error handling in main()
authorMichal Malý <madcatxster@devoid-pointer.net>
Wed, 9 Jul 2014 10:14:35 +0000 (12:14 +0200)
committerMichal Malý <madcatxster@devoid-pointer.net>
Wed, 9 Jul 2014 10:14:35 +0000 (12:14 +0200)
main.c

diff --git a/main.c b/main.c
index 5738a61fdf9bf767a6e70d620fa21cdaf24aa6fe..9e0b9797369fa153ca746cd6106b9069c36377c8 100644 (file)
--- 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;
 }