aboutsummaryrefslogtreecommitdiffstats
path: root/src/initlog.c
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2005-03-31 21:39:24 +0000
committerBill Nottingham <notting@redhat.com>2005-03-31 21:39:24 +0000
commit170aa264f196111dd4a644fe81f08a300566bcd1 (patch)
tree0cc303f341a99a6d9541dba0048164cb0b14dc30 /src/initlog.c
parent44e946f166e0638cbeff106244b69d18707e1784 (diff)
downloadinitscripts-170aa264f196111dd4a644fe81f08a300566bcd1.tar
initscripts-170aa264f196111dd4a644fe81f08a300566bcd1.tar.gz
initscripts-170aa264f196111dd4a644fe81f08a300566bcd1.tar.bz2
initscripts-170aa264f196111dd4a644fe81f08a300566bcd1.tar.xz
initscripts-170aa264f196111dd4a644fe81f08a300566bcd1.zip
free some of the more egregious memory leaks (#85935)
Diffstat (limited to 'src/initlog.c')
-rw-r--r--src/initlog.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/src/initlog.c b/src/initlog.c
index ccf6375b..515c3c73 100644
--- a/src/initlog.c
+++ b/src/initlog.c
@@ -51,7 +51,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;
@@ -60,7 +60,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);
free(data);
@@ -110,6 +110,7 @@ void readConfiguration(char *fname) {
}
if (lfac!=-1) logfacility=lfac;
if (lpri!=-1) logpriority=lpri;
+ free(d);
}
char *getLine(char **data) {
@@ -245,7 +246,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) {
@@ -256,8 +257,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;
@@ -269,11 +272,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));
@@ -287,7 +294,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) {