From a542515f9efa4c0211c24baf5f17edc0badd98eb Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Fri, 26 Mar 2010 01:52:39 +0100 Subject: [PATCH] Fix memory leaks --- include/data.h | 3 --- src/cfgparse.y | 36 ++++++++++++++++++++++++------------ src/randr.c | 5 ++--- 3 files changed, 26 insertions(+), 18 deletions(-) diff --git a/include/data.h b/include/data.h index 2d8c7b1a..3618dfb8 100644 --- a/include/data.h +++ b/include/data.h @@ -212,9 +212,6 @@ struct Workspace { /** The name of the RandR output this screen should be on */ char *preferred_output; - /** Temporary flag needed for re-querying xinerama screens */ - bool reassigned; - /** True if any client on this workspace has its urgent flag set */ bool urgent; diff --git a/src/cfgparse.y b/src/cfgparse.y index b9fae726..e2b03412 100644 --- a/src/cfgparse.y +++ b/src/cfgparse.y @@ -176,6 +176,14 @@ void parse_file(const char *f) { free(context); free(new); free(buf); + + while (!SLIST_EMPTY(&variables)) { + current = SLIST_FIRST(&variables); + FREE(current->key); + FREE(current->value); + SLIST_REMOVE_HEAD(&variables, variables); + FREE(current); + } } %} @@ -279,7 +287,7 @@ bind: new->keycode = $2; new->mods = $1; - new->command = sstrdup($4); + new->command = $4; $$ = new; } @@ -291,9 +299,9 @@ bindsym: printf("\tFound symbolic mod%d with key %s and command %s\n", $1, $2, $4); Binding *new = scalloc(sizeof(Binding)); - new->symbol = sstrdup($2); + new->symbol = $2; new->mods = $1; - new->command = sstrdup($4); + new->command = $4; $$ = new; } @@ -323,7 +331,7 @@ mode: } struct Mode *mode = scalloc(sizeof(struct Mode)); - mode->name = strdup($3); + mode->name = $3; mode->bindings = current_bindings; current_bindings = NULL; SLIST_INSERT_HEAD(&modes, mode, modes); @@ -403,7 +411,7 @@ new_window: TOKNEWWINDOW WHITESPACE WORD { DLOG("new windows should start in mode %s\n", $3); - config.default_border = strdup($3); + config.default_border = sstrdup($3); } ; @@ -447,9 +455,11 @@ workspace: DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); } else { Workspace *ws = workspace_get(ws_num - 1); - ws->preferred_output = sstrdup($7); - if ($8 != NULL) + ws->preferred_output = $7; + if ($8 != NULL) { workspace_set_name(ws, $8); + free($8); + } } } | TOKWORKSPACE WHITESPACE NUMBER WHITESPACE workspace_name @@ -459,8 +469,10 @@ workspace: DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); } else { DLOG("workspace name to: %s\n", $5); - if ($5 != NULL) + if ($5 != NULL) { workspace_set_name(workspace_get(ws_num - 1), $5); + free($5); + } } } ; @@ -484,7 +496,7 @@ assign: struct Assignment *new = $6; printf(" to %d\n", new->workspace); printf(" floating = %d\n", new->floating); - new->windowclass_title = strdup($3); + new->windowclass_title = $3; TAILQ_INSERT_TAIL(&assignments, new, assignments); } ; @@ -525,7 +537,7 @@ optional_arrow: ipcsocket: TOKIPCSOCKET WHITESPACE STR { - config.ipc_socket_path = sstrdup($3); + config.ipc_socket_path = $3; } ; @@ -533,7 +545,7 @@ exec: TOKEXEC WHITESPACE STR { struct Autostart *new = smalloc(sizeof(struct Autostart)); - new->command = sstrdup($3); + new->command = $3; TAILQ_INSERT_TAIL(&autostarts, new, autostarts); } ; @@ -549,7 +561,7 @@ terminal: font: TOKFONT WHITESPACE STR { - config.font = sstrdup($3); + config.font = $3; printf("font %s\n", config.font); } ; diff --git a/src/randr.c b/src/randr.c index d46ffbc4..e61fd9b2 100644 --- a/src/randr.c +++ b/src/randr.c @@ -311,6 +311,7 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id, if (!existing) new = scalloc(sizeof(Output)); new->id = id; + FREE(new->name); asprintf(&new->name, "%.*s", xcb_randr_get_output_info_name_length(output), xcb_randr_get_output_info_name(output)); @@ -325,7 +326,6 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id, TAILQ_INSERT_TAIL(&outputs, new, outputs); else if (new->active) new->to_be_disabled = true; - free(output); return; } @@ -335,7 +335,6 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id, DLOG("Skipping output %s: could not get CRTC (%p)\n", new->name, crtc); free(new); - free(output); return; } @@ -359,7 +358,6 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id, if (!updated || !existing) { if (!existing) TAILQ_INSERT_TAIL(&outputs, new, outputs); - free(output); return; } @@ -409,6 +407,7 @@ void randr_query_outputs(xcb_connection_t *conn) { continue; handle_output(conn, randr_outputs[i], output, cts, res); + free(output); } free(res); -- 2.39.5