diff options
author | Bill Nottingham <notting@redhat.com> | 2005-03-31 21:43:17 +0000 |
---|---|---|
committer | Bill Nottingham <notting@redhat.com> | 2005-03-31 21:43:17 +0000 |
commit | a91fc41ad25047900b3e987f1eac2da4145cbe38 (patch) | |
tree | 386e2a175454da987151acbb27b79cb9e0154fda /src/initlog.c | |
parent | c28bd6f9b55f129bf92b749e84345a6b453ad25a (diff) | |
download | initscripts-a91fc41ad25047900b3e987f1eac2da4145cbe38.tar initscripts-a91fc41ad25047900b3e987f1eac2da4145cbe38.tar.gz initscripts-a91fc41ad25047900b3e987f1eac2da4145cbe38.tar.bz2 initscripts-a91fc41ad25047900b3e987f1eac2da4145cbe38.tar.xz initscripts-a91fc41ad25047900b3e987f1eac2da4145cbe38.zip |
free some of the more egregious memory leaks (#85935)
Diffstat (limited to 'src/initlog.c')
-rw-r--r-- | src/initlog.c | 24 |
1 files changed, 17 insertions, 7 deletions
diff --git a/src/initlog.c b/src/initlog.c index 23f5c508..e9b8e265 100644 --- a/src/initlog.c +++ b/src/initlog.c @@ -40,7 +40,7 @@ struct logInfo *logData = NULL; void readConfiguration(char *fname) { int fd,num=0; struct stat sbuf; - char *data,*line; + char *data,*line, *d; regex_t *regexp; int lfac=-1,lpri=-1; @@ -49,7 +49,7 @@ void readConfiguration(char *fname) { close(fd); return; } - data=malloc(sbuf.st_size+1); + d = data=malloc(sbuf.st_size+1); if (read(fd,data,sbuf.st_size)!=sbuf.st_size) { close(fd); return; @@ -98,6 +98,7 @@ void readConfiguration(char *fname) { } if (lfac!=-1) logfacility=lfac; if (lpri!=-1) logpriority=lpri; + free(d); } char *getLine(char **data) { @@ -267,7 +268,7 @@ int logEvent(char *cmd, int eventtype,char *string) { /* insert more here */ NULL }; - int x=0,len; + int x=0,len, rc; struct logInfo logentry; if (cmd) { @@ -278,8 +279,10 @@ int logEvent(char *cmd, int eventtype,char *string) { logentry.cmd+=3; } else logentry.cmd = strdup(_("(none)")); - if (!string) - string = strdup(cmd); + if (!string) { + string = alloca(strlen(cmd)+1); + strcpy(string,cmd); + } while (eventtable[x] && x<eventtype) x++; if (!(eventtable[x])) x=0; @@ -291,11 +294,15 @@ int logEvent(char *cmd, int eventtype,char *string) { logentry.pri = logpriority; logentry.fac = logfacility; - return logLine(&logentry); + rc = logLine(&logentry); + free(logentry.line); + free(logentry.cmd); + return rc; } int logString(char *cmd, char *string) { struct logInfo logentry; + int rc; if (cmd) { logentry.cmd = strdup(basename(cmd)); @@ -309,7 +316,10 @@ int logString(char *cmd, char *string) { logentry.pri = logpriority; logentry.fac = logfacility; - return logLine(&logentry); + rc = logLine(&logentry); + free(logentry.line); + free(logentry.cmd); + return rc; } int processArgs(int argc, char **argv, int silent) { |