From: Tollef Fog Heen Date: Wed, 26 Dec 2007 09:09:28 +0000 (+0100) Subject: Don't access uninitialised memory X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2d6f6f0ae46729505a0e46fe74aa23766d9cb2e2;p=dpkg Don't access uninitialised memory Trivial fix to make sure we allocate memory before trying to access where a pointer points. --- 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));