Apply patch from Scott Lamb fixing some memory and resource leaks.

This commit is contained in:
Guus Sliepen 2007-02-14 09:21:34 +00:00
parent 6c6535a416
commit 45fca3c723
2 changed files with 13 additions and 6 deletions

View file

@ -84,8 +84,13 @@ pid_t write_pid (char *pidfile)
int fd; int fd;
pid_t pid; pid_t pid;
if ( ((fd = open(pidfile, O_RDWR|O_CREAT, 0644)) == -1) if ((fd = open(pidfile, O_RDWR|O_CREAT, 0644)) == -1) {
|| ((f = fdopen(fd, "r+")) == NULL) ) { close(fd);
return 0;
}
if ((f = fdopen(fd, "r+")) == NULL) {
fclose(f);
return 0; return 0;
} }
@ -98,18 +103,18 @@ pid_t write_pid (char *pidfile)
pid = getpid(); pid = getpid();
if (!fprintf(f,"%ld\n", (long)pid)) { if (!fprintf(f,"%ld\n", (long)pid)) {
close(fd); fclose(f);
return 0; return 0;
} }
fflush(f); fflush(f);
#ifdef HAVE_FLOCK #ifdef HAVE_FLOCK
if (flock(fd, LOCK_UN) == -1) { if (flock(fd, LOCK_UN) == -1) {
close(fd); fclose(f);
return 0; return 0;
} }
#endif #endif
close(fd); fclose(f);
return pid; return pid;
} }

View file

@ -379,8 +379,10 @@ bool execute_script(const char *name, char **envp)
/* First check if there is a script */ /* First check if there is a script */
if(stat(scriptname + 1, &s)) if(stat(scriptname + 1, &s)) {
free(scriptname);
return true; return true;
}
ifdebug(STATUS) logger(LOG_INFO, _("Executing script %s"), name); ifdebug(STATUS) logger(LOG_INFO, _("Executing script %s"), name);