Fix more leaks

- get_parent_pid: free buffer returned from read_line after use.
 - workspace_for_pid: ensure free_pid_workspace is called when
   pid_workspaces are removed from config->pid_workspaces.
 - cmd_split: return the cmd_results from _do_split, so that the
   parent function may free it.
This commit is contained in:
Dan Robertson 2018-02-11 20:08:56 +00:00
parent 4a76d06f33
commit 15f9c89e84
No known key found for this signature in database
GPG key ID: 45C4A652C47E42A5
3 changed files with 6 additions and 5 deletions

View file

@ -96,6 +96,7 @@ pid_t get_parent_pid(pid_t child) {
parent = strtol(token, NULL, 10);
}
free(buffer);
fclose(stat);
}

View file

@ -62,22 +62,21 @@ struct cmd_results *cmd_split(int argc, char **argv) {
return error;
}
if (strcasecmp(argv[0], "v") == 0 || strcasecmp(argv[0], "vertical") == 0) {
_do_split(argc - 1, argv + 1, L_VERT);
return _do_split(argc - 1, argv + 1, L_VERT);
} else if (strcasecmp(argv[0], "h") == 0 || strcasecmp(argv[0], "horizontal") == 0) {
_do_split(argc - 1, argv + 1, L_HORIZ);
return _do_split(argc - 1, argv + 1, L_HORIZ);
} else if (strcasecmp(argv[0], "t") == 0 || strcasecmp(argv[0], "toggle") == 0) {
swayc_t *focused = current_container;
if (focused->parent->layout == L_VERT) {
_do_split(argc - 1, argv + 1, L_HORIZ);
return _do_split(argc - 1, argv + 1, L_HORIZ);
} else {
_do_split(argc - 1, argv + 1, L_VERT);
return _do_split(argc - 1, argv + 1, L_VERT);
}
} else {
error = cmd_results_new(CMD_FAILURE, "split",
"Invalid split command (expected either horizontal or vertical).");
return error;
}
return cmd_results_new(CMD_SUCCESS, NULL, NULL);
}
struct cmd_results *cmd_splitv(int argc, char **argv) {

View file

@ -368,6 +368,7 @@ swayc_t *workspace_for_pid(pid_t pid) {
ws = workspace_create(pw->workspace);
}
free_pid_workspace(pw);
list_del(config->pid_workspaces, i);
}