]> git.sur5r.net Git - i3/i3/commitdiff
fix some memory leaks when user passes command line arguments twice (Thanks Tiago)
authorMichael Stapelberg <michael@stapelberg.de>
Wed, 12 Jan 2011 09:12:24 +0000 (10:12 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Wed, 12 Jan 2011 09:12:24 +0000 (10:12 +0100)
i3-input/i3-input.h
i3-input/main.c
i3-msg/main.c
src/main.c

index 8d8b467f874af0faab5d6fd532494c0717bd3e88..c699f6c560058fdca0f1be7bb07598e224522e7c 100644 (file)
@@ -4,6 +4,13 @@
 #include <err.h>
 
 #define die(...) errx(EXIT_FAILURE, __VA_ARGS__);
+#define FREE(pointer) do { \
+        if (pointer != NULL) { \
+                free(pointer); \
+                pointer = NULL; \
+        } \
+} \
+while (0)
 
 char *convert_ucs_to_utf8(char *input);
 char *convert_utf8_to_ucs2(char *input, int *real_strlen);
index 1010e584c15b924c13a2873ddedd3924b13726d1..6c2b35a193f76149a5c1645a38815fae923889e0 100644 (file)
@@ -261,21 +261,25 @@ int main(int argc, char *argv[]) {
         while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
                 switch (o) {
                         case 's':
+                                FREE(socket_path);
                                 socket_path = strdup(optarg);
                                 break;
                         case 'v':
                                 printf("i3-input " I3_VERSION);
                                 return 0;
                         case 'p':
+                                FREE(command_prefix);
                                 command_prefix = strdup(optarg);
                                 break;
                         case 'l':
                                 limit = atoi(optarg);
                                 break;
                         case 'P':
+                                FREE(prompt);
                                 prompt = strdup(optarg);
                                 break;
                         case 'f':
+                                FREE(pattern);
                                 pattern = strdup(optarg);
                                 break;
                         case 'h':
index a945d3b173330559c93214630f15db64bd3067f6..a2cd9e0a88558e53dee18d90669fb565845dfa0e 100644 (file)
@@ -126,6 +126,8 @@ int main(int argc, char *argv[]) {
 
         while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
                 if (o == 's') {
+                        if (socket_path != NULL)
+                                free(socket_path);
                         socket_path = strdup(optarg);
                 } else if (o == 't') {
                         if (strcasecmp(optarg, "command") == 0)
index ea7f82f23b63b29553331d8ec0d58b6f14d7bc72..64a6e3090b53c7138bfdcce54bdd7bd56066a893 100644 (file)
@@ -108,10 +108,12 @@ int main(int argc, char *argv[]) {
                 autostart = false;
                 break;
             case 'L':
+                FREE(layout_path);
                 layout_path = sstrdup(optarg);
                 delete_layout_path = false;
                 break;
             case 'c':
+                FREE(override_configpath);
                 override_configpath = sstrdup(optarg);
                 break;
             case 'C':
@@ -141,6 +143,7 @@ int main(int argc, char *argv[]) {
                          "and disable this option as soon as you can.\n");
                     break;
                 } else if (strcmp(long_options[option_index].name, "restart") == 0) {
+                    FREE(layout_path);
                     layout_path = sstrdup(optarg);
                     delete_layout_path = true;
                     break;