fix some memory leaks when user passes command line arguments twice (Thanks Tiago)
This commit is contained in:
parent
a6f0dcd250
commit
cd2ee61ee8
|
@ -4,6 +4,13 @@
|
||||||
#include <err.h>
|
#include <err.h>
|
||||||
|
|
||||||
#define die(...) errx(EXIT_FAILURE, __VA_ARGS__);
|
#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_ucs_to_utf8(char *input);
|
||||||
char *convert_utf8_to_ucs2(char *input, int *real_strlen);
|
char *convert_utf8_to_ucs2(char *input, int *real_strlen);
|
||||||
|
|
|
@ -261,21 +261,25 @@ int main(int argc, char *argv[]) {
|
||||||
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
|
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
|
||||||
switch (o) {
|
switch (o) {
|
||||||
case 's':
|
case 's':
|
||||||
|
FREE(socket_path);
|
||||||
socket_path = strdup(optarg);
|
socket_path = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'v':
|
case 'v':
|
||||||
printf("i3-input " I3_VERSION);
|
printf("i3-input " I3_VERSION);
|
||||||
return 0;
|
return 0;
|
||||||
case 'p':
|
case 'p':
|
||||||
|
FREE(command_prefix);
|
||||||
command_prefix = strdup(optarg);
|
command_prefix = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'l':
|
case 'l':
|
||||||
limit = atoi(optarg);
|
limit = atoi(optarg);
|
||||||
break;
|
break;
|
||||||
case 'P':
|
case 'P':
|
||||||
|
FREE(prompt);
|
||||||
prompt = strdup(optarg);
|
prompt = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'f':
|
case 'f':
|
||||||
|
FREE(pattern);
|
||||||
pattern = strdup(optarg);
|
pattern = strdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
|
|
|
@ -126,6 +126,8 @@ int main(int argc, char *argv[]) {
|
||||||
|
|
||||||
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
|
while ((o = getopt_long(argc, argv, options_string, long_options, &option_index)) != -1) {
|
||||||
if (o == 's') {
|
if (o == 's') {
|
||||||
|
if (socket_path != NULL)
|
||||||
|
free(socket_path);
|
||||||
socket_path = strdup(optarg);
|
socket_path = strdup(optarg);
|
||||||
} else if (o == 't') {
|
} else if (o == 't') {
|
||||||
if (strcasecmp(optarg, "command") == 0)
|
if (strcasecmp(optarg, "command") == 0)
|
||||||
|
|
|
@ -108,10 +108,12 @@ int main(int argc, char *argv[]) {
|
||||||
autostart = false;
|
autostart = false;
|
||||||
break;
|
break;
|
||||||
case 'L':
|
case 'L':
|
||||||
|
FREE(layout_path);
|
||||||
layout_path = sstrdup(optarg);
|
layout_path = sstrdup(optarg);
|
||||||
delete_layout_path = false;
|
delete_layout_path = false;
|
||||||
break;
|
break;
|
||||||
case 'c':
|
case 'c':
|
||||||
|
FREE(override_configpath);
|
||||||
override_configpath = sstrdup(optarg);
|
override_configpath = sstrdup(optarg);
|
||||||
break;
|
break;
|
||||||
case 'C':
|
case 'C':
|
||||||
|
@ -141,6 +143,7 @@ int main(int argc, char *argv[]) {
|
||||||
"and disable this option as soon as you can.\n");
|
"and disable this option as soon as you can.\n");
|
||||||
break;
|
break;
|
||||||
} else if (strcmp(long_options[option_index].name, "restart") == 0) {
|
} else if (strcmp(long_options[option_index].name, "restart") == 0) {
|
||||||
|
FREE(layout_path);
|
||||||
layout_path = sstrdup(optarg);
|
layout_path = sstrdup(optarg);
|
||||||
delete_layout_path = true;
|
delete_layout_path = true;
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in New Issue