From: Michael Stapelberg Date: Mon, 19 Oct 2015 17:11:53 +0000 (+0200) Subject: fix a memory leak in handle_get_bar_config X-Git-Tag: 4.12~127 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=8125b54e09aa2ec06367245d8132241a8ee682ae;p=i3%2Fi3 fix a memory leak in handle_get_bar_config --- diff --git a/src/ipc.c b/src/ipc.c index 1a8d28ed..c884cc8e 100644 --- a/src/ipc.c +++ b/src/ipc.c @@ -894,8 +894,8 @@ IPC_HANDLER(get_bar_config) { /* To get a properly terminated buffer, we copy * message_size bytes out of the buffer */ - char *bar_id = scalloc(message_size + 1, 1); - strncpy(bar_id, (const char *)message, message_size); + char *bar_id = NULL; + sasprintf(&bar_id, "%.*s", message_size, message); LOG("IPC: looking for config for bar ID \"%s\"\n", bar_id); Barconfig *current, *config = NULL; TAILQ_FOREACH(current, &barconfigs, configs) { @@ -905,6 +905,7 @@ IPC_HANDLER(get_bar_config) { config = current; break; } + free(bar_id); if (!config) { /* If we did not find a config for the given ID, the reply will contain