Commit Diff
- Commit:
d9934b8e3ee43c47ce6f49c8da8ccfeed6977afd- From:
- Brett Fisher <code@brettfisher.xyz>
- Date:
- Message:
- bxnotify.c: Refactor error and exit handling for suite consistency. - Update the cleanup() function signature to accept an integer error code (int err), allowing the function to terminate the process via exit() based on runtime success or failure. - Modify die() to call cleanup(1) instead of exit(1), ensuring all resources (X11 connections, text buffers, registry positions) are properly freed even when terminating due to an error. - Update the successful exit path in main() to call cleanup(0). - Remove the explicit 'return 0' from main(), as cleanup() now handles process termination directly. - Ensure the forward declaration for cleanup() matches the updated implementation to prevent C11 type-mismatch warnings.
- Actions:
- Patch | Tree
--- bxnotify.c +++ bxnotify.c @@ -55,7 +55,7 @@ static const char *cfg_font = FONT; /* Forward Declarations */ static void die(const char *fmt, ...); -static void cleanup(void); +static void cleanup(int err); static void sigusr1(int sig); static int measure_text(const char *text); static int (*xerrorxlib)(Display *, XErrorEvent *); @@ -99,9 +99,7 @@ main(int argc, char *argv[]) start_time = time(NULL); run(); - cleanup(); - - return 0; + cleanup(0); } static void @@ -111,11 +109,11 @@ die(const char *fmt, ...) va_start(ap, fmt); vfprintf(stderr, fmt, ap); va_end(ap); - exit(1); + cleanup(1); } static void -cleanup(void) +cleanup(int err) { unregister_position(); @@ -127,6 +125,8 @@ cleanup(void) if (font) XftFontClose(dpy, font); if (win) XDestroyWindow(dpy, win); if (dpy) XCloseDisplay(dpy); + + exit(err); } static void
