From 2d6f6f0ae46729505a0e46fe74aa23766d9cb2e2 Mon Sep 17 00:00:00 2001 From: Tollef Fog Heen Date: Wed, 26 Dec 2007 10:09:28 +0100 Subject: [PATCH] Don't access uninitialised memory Trivial fix to make sure we allocate memory before trying to access where a pointer points. --- lib/myopt.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/myopt.c b/lib/myopt.c index 3a066c93..64d4122c 100644 --- a/lib/myopt.c +++ b/lib/myopt.c @@ -185,6 +185,11 @@ void loadfilter(char *fn) { while (fgets(linebuf, sizeof(linebuf), file)) { struct filterlist *filter; + filter = malloc(sizeof(struct filterlist)); + if (!filter) { + ohshite(_("Error allocating memory for filter entry")); + } + if (linebuf[0] == '#' || linebuf[0] == '\n') { continue; } @@ -198,11 +203,8 @@ void loadfilter(char *fn) { filter->positive = 0; } else { warningf(_("Invalid filter line: `%.255s'"), linebuf); - } - - filter = malloc(sizeof(struct filterlist)); - if (!filter) { - ohshite(_("Error allocating memory for filter entry")); + free(filter); + continue; } filter->filterstring = malloc(strlen(linebuf)); -- 2.39.5