mirror of
https://github.com/swaywm/sway.git
synced 2024-12-30 17:06:40 +01:00
Merge pull request #10 from taiyu-len/master
fixed small memory leak. v2
This commit is contained in:
commit
caee41b777
1 changed files with 18 additions and 13 deletions
|
@ -346,9 +346,10 @@ struct cmd_handler *find_handler(struct cmd_handler handlers[], int l, char *lin
|
||||||
int handle_command(struct sway_config *config, char *exec) {
|
int handle_command(struct sway_config *config, char *exec) {
|
||||||
sway_log(L_INFO, "Handling command '%s'", exec);
|
sway_log(L_INFO, "Handling command '%s'", exec);
|
||||||
char *ptr, *cmd;
|
char *ptr, *cmd;
|
||||||
|
int ret;
|
||||||
|
|
||||||
if ((ptr = strchr(exec, ' ')) == NULL) {
|
if ((ptr = strchr(exec, ' ')) == NULL) {
|
||||||
cmd = malloc(strlen(exec) + 1);
|
cmd = exec;
|
||||||
strcpy(cmd, exec);
|
|
||||||
} else {
|
} else {
|
||||||
int index = ptr - exec;
|
int index = ptr - exec;
|
||||||
cmd = malloc(index + 1);
|
cmd = malloc(index + 1);
|
||||||
|
@ -358,18 +359,22 @@ int handle_command(struct sway_config *config, char *exec) {
|
||||||
struct cmd_handler *handler = find_handler(handlers, sizeof(handlers) / sizeof(struct cmd_handler), cmd);
|
struct cmd_handler *handler = find_handler(handlers, sizeof(handlers) / sizeof(struct cmd_handler), cmd);
|
||||||
if (handler == NULL) {
|
if (handler == NULL) {
|
||||||
sway_log(L_ERROR, "Unknown command '%s'", cmd);
|
sway_log(L_ERROR, "Unknown command '%s'", cmd);
|
||||||
return 0; // TODO: return error, probably
|
ret = 0; // TODO: return error, probably
|
||||||
|
} else {
|
||||||
|
int argc;
|
||||||
|
char **argv = split_directive(exec + strlen(handler->command), &argc);
|
||||||
|
int i;
|
||||||
|
ret = handler->handle(config, argc, argv);
|
||||||
|
for (i = 0; i < argc; ++i) {
|
||||||
|
free(argv[i]);
|
||||||
|
}
|
||||||
|
free(argv);
|
||||||
|
if (ret != 0) {
|
||||||
|
sway_log(L_ERROR, "Command failed: %s", cmd);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
int argc;
|
if(ptr) {
|
||||||
char **argv = split_directive(exec + strlen(handler->command), &argc);
|
free(cmd);
|
||||||
int ret = handler->handle(config, argc, argv);
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < argc; ++i) {
|
|
||||||
free(argv[i]);
|
|
||||||
}
|
|
||||||
free(argv);
|
|
||||||
if (ret != 0) {
|
|
||||||
sway_log(L_ERROR, "Command failed: %s", cmd);
|
|
||||||
}
|
}
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue