From 1bc1f62c7a0ed3edf41faf0cec49cfad2db794b0 Mon Sep 17 00:00:00 2001 From: Lawrence Teo Date: Thu, 19 Jan 2012 21:43:04 -0500 Subject: [PATCH] Plug memory and file descriptor leaks in conf_load(). From: Tiago Cunha ok marco --- scrotwm.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/scrotwm.c b/scrotwm.c index cb56f65..0c339a2 100644 --- a/scrotwm.c +++ b/scrotwm.c @@ -5400,7 +5400,7 @@ conf_load(char *filename, int keymapping) if (wordlen == 0) { warnx("%s: line %zd: no option found", filename, lineno); - return (1); + goto out; } optind = -1; for (i = 0; i < LENGTH(configopt); i++) { @@ -5414,12 +5414,12 @@ conf_load(char *filename, int keymapping) if (optind == -1) { warnx("%s: line %zd: unknown option %.*s", filename, lineno, wordlen, cp); - return (1); + goto out; } if (keymapping && strcmp(opt->optname, "bind")) { warnx("%s: line %zd: invalid option %.*s", filename, lineno, wordlen, cp); - return (1); + goto out; } cp += wordlen; cp += strspn(cp, " \t\n"); /* eat whitespace */ @@ -5432,7 +5432,7 @@ conf_load(char *filename, int keymapping) if (wordlen == 0) { warnx("%s: line %zd: syntax error", filename, lineno); - return (1); + goto out; } asprintf(&optsub, "%.*s", wordlen, cp); } @@ -5459,6 +5459,12 @@ conf_load(char *filename, int keymapping) DNPRINTF(SWM_D_CONF, "conf_load end\n"); return (0); + +out: + free(line); + fclose(config); + + return (1); } void -- 1.7.10.4