summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBill Nottingham <notting@redhat.com>2005-03-31 21:39:44 +0000
committerBill Nottingham <notting@redhat.com>2005-03-31 21:39:44 +0000
commit79c68ff64cd50f71322e748b136a51073d5b3a03 (patch)
tree743d4815d952527527bd69a416105ce0d6d0169c
parent3e95620ace47c8f1f732d3efc963b8dc5a92f4e6 (diff)
downloadinitscripts-79c68ff64cd50f71322e748b136a51073d5b3a03.tar.gz
initscripts-79c68ff64cd50f71322e748b136a51073d5b3a03.tar.xz
initscripts-79c68ff64cd50f71322e748b136a51073d5b3a03.zip
free some of the more egregious memory leaks (#85935)
-rw-r--r--src/initlog.c24
-rw-r--r--src/process.c10
2 files changed, 25 insertions, 9 deletions
diff --git a/src/initlog.c b/src/initlog.c
index 3b1cded6..19d9f9aa 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) {
@@ -279,7 +280,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) {
@@ -290,8 +291,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;
@@ -303,11 +306,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));
@@ -321,7 +328,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) {
diff --git a/src/process.c b/src/process.c
index c17680bf..0eec34ac 100644
--- a/src/process.c
+++ b/src/process.c
@@ -188,7 +188,8 @@ int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet,
int bytesread = 0;
do {
- char *buf=calloc(8192,sizeof(char));
+ char *b, *buf=calloc(8192,sizeof(char));
+ b = buf;
bytesread = read(pfds[y].fd,buf,8192);
if (bytesread==-1) {
perror("read");
@@ -251,11 +252,16 @@ int monitor(char *cmdname, int pid, int numfds, int *fds, int reexec, int quiet,
}
cmdargs[cmdargc+1]=NULL;
processArgs(cmdargc+1,cmdargs,1);
+ for (z=0;z<(cmdargc);z++) {
+ free(cmdargs[z]);
+ }
+ free(cmdargs);
}
}
+ if (tmpstr) free(tmpstr);
}
}
- free(buf);
+ free(b);
} while ( bytesread==8192 );
}
y++;