From: Fernando Tarlá Cardoso Lemos Date: Sun, 6 Nov 2011 22:03:47 +0000 (-0200) Subject: Don't call free on statically allocated strings. X-Git-Tag: 4.1~29 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=af335f0403567e783ebad2d4e4e0da0ac19b4757;p=i3%2Fi3 Don't call free on statically allocated strings. Fixes segfault when the option -f is used. Also, don't leak prompt strings. We either keep FREE to prevent leaking, or choose to leak and avoid strdup. Another option would be using a flag to indicate whether or not the strings are heap allocated, but it's overkill. --- diff --git a/i3-nagbar/main.c b/i3-nagbar/main.c index 70ded8d8..4d4e253a 100644 --- a/i3-nagbar/main.c +++ b/i3-nagbar/main.c @@ -41,7 +41,7 @@ static xcb_pixmap_t pixmap; static xcb_gcontext_t pixmap_gc; static xcb_rectangle_t rect = { 0, 0, 600, 20 }; static i3Font font; -static char *prompt = "Please do not run this program."; +static char *prompt; static button_t *buttons; static int buttoncnt; @@ -220,7 +220,7 @@ static int handle_expose(xcb_connection_t *conn, xcb_expose_event_t *event) { } int main(int argc, char *argv[]) { - char *pattern = "-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"; + char *pattern = strdup("-misc-fixed-medium-r-normal--13-120-75-75-C-70-iso10646-1"); int o, option_index = 0; enum { TYPE_ERROR = 0, TYPE_WARNING = 1 } bar_type = TYPE_ERROR; @@ -236,6 +236,8 @@ int main(int argc, char *argv[]) { char *options_string = "b:f:m:t:vh"; + prompt = strdup("Please do not run this program."); + while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) { switch (o) { case 'v': @@ -246,6 +248,7 @@ int main(int argc, char *argv[]) { pattern = strdup(optarg); break; case 'm': + FREE(prompt); prompt = strdup(optarg); break; case 't':