]> git.sur5r.net Git - i3/i3/commitdiff
fix a memory leak in handle_get_bar_config
authorMichael Stapelberg <michael@stapelberg.de>
Mon, 19 Oct 2015 17:11:53 +0000 (19:11 +0200)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 28 Oct 2015 20:56:39 +0000 (21:56 +0100)
src/ipc.c

index 1a8d28ed218189c073be4c40e9113cf8a56d9414..c884cc8e8819ec9d4872ea051aa03c71b4bed290 100644 (file)
--- 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