From ed067579b9b4a32c68ad11ab6ff9303f9932cdaf Mon Sep 17 00:00:00 2001 From: Georg Reinke Date: Tue, 24 Jul 2012 14:12:04 +0200 Subject: [PATCH] Correct cleanup() behaviour --- bar.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/bar.c b/bar.c index c84921e..5b5bf11 100644 --- a/bar.c +++ b/bar.c @@ -360,14 +360,22 @@ init (void) void cleanup (void) { - xcb_close_font (c, fontset[FONT_MAIN].xcb_ft); - xcb_close_font (c, fontset[FONT_FALLBACK].xcb_ft); - xcb_free_pixmap (c, canvas); - xcb_destroy_window (c, win); - xcb_free_gc (c, draw_gc); - xcb_free_gc (c, clear_gc); - xcb_free_gc (c, underl_gc); - xcb_disconnect (c); + if (fontset[FONT_MAIN].xcb_ft) + xcb_close_font (c, fontset[FONT_MAIN].xcb_ft); + if (fontset[FONT_FALLBACK].xcb_ft) + xcb_close_font (c, fontset[FONT_FALLBACK].xcb_ft); + if (canvas) + xcb_free_pixmap (c, canvas); + if (win) + xcb_destroy_window (c, win); + if (draw_gc) + xcb_free_gc (c, draw_gc); + if (clear_gc) + xcb_free_gc (c, clear_gc); + if (underl_gc) + xcb_free_gc (c, underl_gc); + if (c) + xcb_disconnect (c); } void @@ -405,10 +413,10 @@ main (int argc, char **argv) } } + atexit (cleanup); signal (SIGINT, sighandle); signal (SIGTERM, sighandle); init (); - atexit (cleanup); /* Get the fd to Xserver */ pollin[1].fd = xcb_get_file_descriptor (c);