Fix memory leaks

This commit is contained in:
Michael Stapelberg 2010-03-26 01:52:39 +01:00
parent 7bd4ea3699
commit a542515f9e
3 changed files with 26 additions and 18 deletions

View File

@ -212,9 +212,6 @@ struct Workspace {
/** The name of the RandR output this screen should be on */ /** The name of the RandR output this screen should be on */
char *preferred_output; 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 */ /** True if any client on this workspace has its urgent flag set */
bool urgent; bool urgent;

View File

@ -176,6 +176,14 @@ void parse_file(const char *f) {
free(context); free(context);
free(new); free(new);
free(buf); 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 = $<number>2; new->keycode = $<number>2;
new->mods = $<number>1; new->mods = $<number>1;
new->command = sstrdup($<string>4); new->command = $<string>4;
$<binding>$ = new; $<binding>$ = new;
} }
@ -291,9 +299,9 @@ bindsym:
printf("\tFound symbolic mod%d with key %s and command %s\n", $<number>1, $<string>2, $<string>4); printf("\tFound symbolic mod%d with key %s and command %s\n", $<number>1, $<string>2, $<string>4);
Binding *new = scalloc(sizeof(Binding)); Binding *new = scalloc(sizeof(Binding));
new->symbol = sstrdup($<string>2); new->symbol = $<string>2;
new->mods = $<number>1; new->mods = $<number>1;
new->command = sstrdup($<string>4); new->command = $<string>4;
$<binding>$ = new; $<binding>$ = new;
} }
@ -323,7 +331,7 @@ mode:
} }
struct Mode *mode = scalloc(sizeof(struct Mode)); struct Mode *mode = scalloc(sizeof(struct Mode));
mode->name = strdup($<string>3); mode->name = $<string>3;
mode->bindings = current_bindings; mode->bindings = current_bindings;
current_bindings = NULL; current_bindings = NULL;
SLIST_INSERT_HEAD(&modes, mode, modes); SLIST_INSERT_HEAD(&modes, mode, modes);
@ -403,7 +411,7 @@ new_window:
TOKNEWWINDOW WHITESPACE WORD TOKNEWWINDOW WHITESPACE WORD
{ {
DLOG("new windows should start in mode %s\n", $<string>3); DLOG("new windows should start in mode %s\n", $<string>3);
config.default_border = strdup($<string>3); config.default_border = sstrdup($<string>3);
} }
; ;
@ -447,9 +455,11 @@ workspace:
DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
} else { } else {
Workspace *ws = workspace_get(ws_num - 1); Workspace *ws = workspace_get(ws_num - 1);
ws->preferred_output = sstrdup($<string>7); ws->preferred_output = $<string>7;
if ($<string>8 != NULL) if ($<string>8 != NULL) {
workspace_set_name(ws, $<string>8); workspace_set_name(ws, $<string>8);
free($<string>8);
}
} }
} }
| TOKWORKSPACE WHITESPACE NUMBER WHITESPACE workspace_name | TOKWORKSPACE WHITESPACE NUMBER WHITESPACE workspace_name
@ -459,8 +469,10 @@ workspace:
DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num); DLOG("Invalid workspace assignment, workspace number %d out of range\n", ws_num);
} else { } else {
DLOG("workspace name to: %s\n", $<string>5); DLOG("workspace name to: %s\n", $<string>5);
if ($<string>5 != NULL) if ($<string>5 != NULL) {
workspace_set_name(workspace_get(ws_num - 1), $<string>5); workspace_set_name(workspace_get(ws_num - 1), $<string>5);
free($<string>5);
}
} }
} }
; ;
@ -484,7 +496,7 @@ assign:
struct Assignment *new = $<assignment>6; struct Assignment *new = $<assignment>6;
printf(" to %d\n", new->workspace); printf(" to %d\n", new->workspace);
printf(" floating = %d\n", new->floating); printf(" floating = %d\n", new->floating);
new->windowclass_title = strdup($<string>3); new->windowclass_title = $<string>3;
TAILQ_INSERT_TAIL(&assignments, new, assignments); TAILQ_INSERT_TAIL(&assignments, new, assignments);
} }
; ;
@ -525,7 +537,7 @@ optional_arrow:
ipcsocket: ipcsocket:
TOKIPCSOCKET WHITESPACE STR TOKIPCSOCKET WHITESPACE STR
{ {
config.ipc_socket_path = sstrdup($<string>3); config.ipc_socket_path = $<string>3;
} }
; ;
@ -533,7 +545,7 @@ exec:
TOKEXEC WHITESPACE STR TOKEXEC WHITESPACE STR
{ {
struct Autostart *new = smalloc(sizeof(struct Autostart)); struct Autostart *new = smalloc(sizeof(struct Autostart));
new->command = sstrdup($<string>3); new->command = $<string>3;
TAILQ_INSERT_TAIL(&autostarts, new, autostarts); TAILQ_INSERT_TAIL(&autostarts, new, autostarts);
} }
; ;
@ -549,7 +561,7 @@ terminal:
font: font:
TOKFONT WHITESPACE STR TOKFONT WHITESPACE STR
{ {
config.font = sstrdup($<string>3); config.font = $<string>3;
printf("font %s\n", config.font); printf("font %s\n", config.font);
} }
; ;

View File

@ -311,6 +311,7 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id,
if (!existing) if (!existing)
new = scalloc(sizeof(Output)); new = scalloc(sizeof(Output));
new->id = id; new->id = id;
FREE(new->name);
asprintf(&new->name, "%.*s", asprintf(&new->name, "%.*s",
xcb_randr_get_output_info_name_length(output), xcb_randr_get_output_info_name_length(output),
xcb_randr_get_output_info_name(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); TAILQ_INSERT_TAIL(&outputs, new, outputs);
else if (new->active) else if (new->active)
new->to_be_disabled = true; new->to_be_disabled = true;
free(output);
return; 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", DLOG("Skipping output %s: could not get CRTC (%p)\n",
new->name, crtc); new->name, crtc);
free(new); free(new);
free(output);
return; return;
} }
@ -359,7 +358,6 @@ static void handle_output(xcb_connection_t *conn, xcb_randr_output_t id,
if (!updated || !existing) { if (!updated || !existing) {
if (!existing) if (!existing)
TAILQ_INSERT_TAIL(&outputs, new, outputs); TAILQ_INSERT_TAIL(&outputs, new, outputs);
free(output);
return; return;
} }
@ -409,6 +407,7 @@ void randr_query_outputs(xcb_connection_t *conn) {
continue; continue;
handle_output(conn, randr_outputs[i], output, cts, res); handle_output(conn, randr_outputs[i], output, cts, res);
free(output);
} }
free(res); free(res);