Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix a few possible memory leaks #80

Merged
merged 1 commit into from
Aug 19, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions sway/commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ static bool cmd_bindsym(struct sway_config *config, int argc, char **argv) {
xkb_keysym_t sym = xkb_keysym_from_name(split->items[i], XKB_KEYSYM_CASE_INSENSITIVE);
if (!sym) {
sway_log(L_ERROR, "bindsym - unknown key %s", (char *)split->items[i]);
list_free(binding->keys);
free(binding->command);
free(binding);
list_free(split);
return false;
}
xkb_keysym_t *key = malloc(sizeof(xkb_keysym_t));
Expand Down
6 changes: 6 additions & 0 deletions sway/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ static char *get_config_path() {
if (exists(temp)) {
return temp;
}
free(temp);

// Check XDG_CONFIG_HOME with fallback to ~/.config/
sway_log(L_DEBUG, "Trying to find config in XDG_CONFIG_HOME/sway/config");
Expand All @@ -54,6 +55,7 @@ static char *get_config_path() {
if (exists(temp)) {
return temp;
}
free(temp);

// Check XDG_CONFIG_DIRS
sway_log(L_DEBUG, "Trying to find config in XDG_CONFIG_DIRS");
Expand All @@ -70,6 +72,7 @@ static char *get_config_path() {
free_flat_list(paths);
return temp;
}
free(temp);
}
free_flat_list(paths);
}
Expand All @@ -83,6 +86,7 @@ static char *get_config_path() {
if (exists(temp)) {
return temp;
}
free(temp);

sway_log(L_DEBUG, "Trying to find config in XDG_CONFIG_HOME/i3/config");
if (xdg_config_home == NULL) {
Expand All @@ -106,6 +110,7 @@ static char *get_config_path() {
if (exists(temp)) {
return temp;
}
free(temp);

sway_log(L_DEBUG, "Trying to find config in XDG_CONFIG_DIRS");
if (xdg_config_dirs != NULL) {
Expand All @@ -120,6 +125,7 @@ static char *get_config_path() {
free_flat_list(paths);
return temp;
}
free(temp);
}
free_flat_list(paths);
}
Expand Down
15 changes: 10 additions & 5 deletions sway/workspace.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ char *workspace_next_name(void) {
char* target = malloc(strlen(args->items[1]) + 1);
strcpy(target, args->items[1]);
while (*target == ' ' || *target == '\t')
target++;
target++;

// Make sure that the command references an actual workspace
// not a command about workspaces
Expand All @@ -42,18 +42,23 @@ char *workspace_next_name(void) {
strcmp(target, "number") == 0 ||
strcmp(target, "back_and_forth") == 0 ||
strcmp(target, "current") == 0)
{
list_free(args);
continue;

//Make sure that the workspace doesn't already exist
}

//Make sure that the workspace doesn't already exist
if (workspace_find_by_name(target)) {
continue;
list_free(args);
continue;
}

list_free(args);

sway_log(L_DEBUG, "Workspace: Found free name %s", target);
return target;
}
list_free(args);
}
// As a fall back, get the current number of active workspaces
// and return that + 1 for the next workspace's name
Expand All @@ -77,7 +82,7 @@ swayc_t *workspace_create(const char* name) {
}

bool workspace_by_name(swayc_t *view, void *data) {
return (view->type == C_WORKSPACE) &&
return (view->type == C_WORKSPACE) &&
(strcasecmp(view->name, (char *) data) == 0);
}

Expand Down