diff --git a/i3-input/i3-input.h b/i3-input/i3-input.h index 8d8b467f..c699f6c5 100644 --- a/i3-input/i3-input.h +++ b/i3-input/i3-input.h @@ -4,6 +4,13 @@ #include #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); diff --git a/i3-input/main.c b/i3-input/main.c index 1010e584..6c2b35a1 100644 --- a/i3-input/main.c +++ b/i3-input/main.c @@ -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': diff --git a/i3-msg/main.c b/i3-msg/main.c index a945d3b1..a2cd9e0a 100644 --- a/i3-msg/main.c +++ b/i3-msg/main.c @@ -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) diff --git a/src/main.c b/src/main.c index ea7f82f2..64a6e309 100644 --- a/src/main.c +++ b/src/main.c @@ -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;