]> git.sur5r.net Git - i3/i3/blobdiff - i3-msg/main.c
Fix memory leaks. (#2530)
[i3/i3] / i3-msg / main.c
index 36691cae471ddeb17cb20322a82f961891757b02..915d326f52052d70dfefe4302b0ca6003bd87e82 100644 (file)
@@ -14,6 +14,8 @@
  * Additionally, it’s even useful sometimes :-).
  *
  */
+#include "libi3.h"
+
 #include <stdio.h>
 #include <stdbool.h>
 #include <sys/types.h>
@@ -34,7 +36,6 @@
 #include <xcb/xcb.h>
 #include <xcb/xcb_aux.h>
 
-#include "libi3.h"
 #include <i3/ipc.h>
 
 static char *socket_path;
@@ -161,11 +162,13 @@ int main(int argc, char *argv[]) {
                 message_type = I3_IPC_MESSAGE_TYPE_GET_MARKS;
             else if (strcasecmp(optarg, "get_bar_config") == 0)
                 message_type = I3_IPC_MESSAGE_TYPE_GET_BAR_CONFIG;
+            else if (strcasecmp(optarg, "get_binding_modes") == 0)
+                message_type = I3_IPC_MESSAGE_TYPE_GET_BINDING_MODES;
             else if (strcasecmp(optarg, "get_version") == 0)
                 message_type = I3_IPC_MESSAGE_TYPE_GET_VERSION;
             else {
                 printf("Unknown message type\n");
-                printf("Known types: command, get_workspaces, get_outputs, get_tree, get_marks, get_bar_config, get_version\n");
+                printf("Known types: command, get_workspaces, get_outputs, get_tree, get_marks, get_bar_config, get_binding_modes, get_version\n");
                 exit(EXIT_FAILURE);
             }
         } else if (o == 'q') {
@@ -203,7 +206,7 @@ int main(int argc, char *argv[]) {
     }
 
     if (!payload)
-        payload = "";
+        payload = sstrdup("");
 
     int sockfd = socket(AF_LOCAL, SOCK_STREAM, 0);
     if (sockfd == -1)
@@ -218,6 +221,7 @@ int main(int argc, char *argv[]) {
 
     if (ipc_send_message(sockfd, strlen(payload), message_type, (uint8_t *)payload) == -1)
         err(EXIT_FAILURE, "IPC: write()");
+    free(payload);
 
     if (quiet)
         return 0;