From: Marcela Mašláňová Date: Mon, 13 Jul 2009 14:33:03 +0000 (+0200) Subject: Memory leaks should be fixed. Instead of log is used slog function. X-Git-Tag: cronie1.4~11 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=91668123196c190d29eb02d200eab074dbfe95bf;p=cronie Memory leaks should be fixed. Instead of log is used slog function. --- diff --git a/anacron/global.h b/anacron/global.h index 9d97af9..38a526b 100644 --- a/anacron/global.h +++ b/anacron/global.h @@ -105,18 +105,25 @@ extern int complaints; /* main.c */ int xopen(int fd, const char *file_name, int flags); void xclose(int fd); -pid_t xfork(); +pid_t xfork(void); + +#ifdef __GNUC__ +#define PRINTF_FORMAT(n, m) \ + __attribute__ ((format (printf, n, m))) +#else +#define PRINTF_FORMAT(n, m) +#endif /* log.c */ -void explain(const char *fmt, ...); -void explain_e(const char *fmt, ...); -void complain(const char *fmt, ...); -void complain_e(const char *fmt, ...); -void die(const char *fmt, ...); -void die_e(const char *fmt, ...); -void xdebug(const char *fmt, ...); -void xdebug_e(const char *fmt, ...); -void xcloselog(); +void explain(const char *fmt, ...)PRINTF_FORMAT(1,2); +void explain_e(const char *fmt, ...)PRINTF_FORMAT(1,2); +void complain(const char *fmt, ...)PRINTF_FORMAT(1,2); +void complain_e(const char *fmt, ...)PRINTF_FORMAT(1,2); +void die(const char *fmt, ...)PRINTF_FORMAT(1,2); +void die_e(const char *fmt, ...)PRINTF_FORMAT(1,2); +void xdebug(const char *fmt, ...)PRINTF_FORMAT(1,2); +void xdebug_e(const char *fmt, ...)PRINTF_FORMAT(1,2); +void xcloselog(void); #ifdef DEBUG #define Debug(args) xdebug args @@ -128,7 +135,7 @@ void xcloselog(); /* readtab.c */ void read_tab(int cwd); -void arrange_jobs(); +void arrange_jobs(void); /* lock.c */ int consider_job(job_rec *jr); diff --git a/anacron/gregor.c b/anacron/gregor.c index d54ba8d..91e4173 100644 --- a/anacron/gregor.c +++ b/anacron/gregor.c @@ -27,7 +27,7 @@ #include #include "gregor.h" -const static int +static const int days_in_month[] = { 31, /* Jan */ 28, /* Feb (non-leap) */ diff --git a/anacron/log.c b/anacron/log.c index 5b430e6..709420c 100644 --- a/anacron/log.c +++ b/anacron/log.c @@ -83,7 +83,7 @@ make_msg(const char *fmt, va_list args) } static void -log(int priority, const char *fmt, va_list args) +slog(int priority, const char *fmt, va_list args) /* Log a message, described by "fmt" and "args", with the specified * "priority". */ { @@ -101,7 +101,7 @@ log(int priority, const char *fmt, va_list args) static void log_e(int priority, const char *fmt, va_list args) -/* Same as log(), but also appends an error description corresponding +/* Same as slog(), but also appends an error description corresponding * to "errno". */ { int saved_errno; @@ -127,7 +127,7 @@ explain(const char *fmt, ...) va_list args; va_start(args, fmt); - log(EXPLAIN_LEVEL, fmt, args); + slog(EXPLAIN_LEVEL, fmt, args); va_end(args); } @@ -149,7 +149,7 @@ complain(const char *fmt, ...) va_list args; va_start(args, fmt); - log(COMPLAIN_LEVEL, fmt, args); + slog(COMPLAIN_LEVEL, fmt, args); va_end(args); complaints += 1; @@ -175,7 +175,7 @@ die(const char *fmt, ...) va_list args; va_start(args, fmt); - log(COMPLAIN_LEVEL, fmt, args); + slog(COMPLAIN_LEVEL, fmt, args); va_end(args); if (getpid() == primary_pid) complain("Aborted"); @@ -207,7 +207,7 @@ xdebug(const char *fmt, ...) va_list args; va_start(args, fmt); - log(DEBUG_LEVEL, fmt, args); + slog(DEBUG_LEVEL, fmt, args); va_end(args); } diff --git a/anacron/matchrx.c b/anacron/matchrx.c index a3e940c..905694e 100644 --- a/anacron/matchrx.c +++ b/anacron/matchrx.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "matchrx.h" int @@ -49,11 +50,20 @@ match_rx(const char *rx, char *string, int n_sub, /* char **substrings */...) sub_offsets = malloc(sizeof(regmatch_t) * (n_sub + 1)); memset(sub_offsets, 0, sizeof(regmatch_t) * (n_sub + 1)); - if (regcomp(&crx, rx, REG_EXTENDED)) return - 1; + if (regcomp(&crx, rx, REG_EXTENDED)) { + free(sub_offsets); + return - 1; + } r = regexec(&crx, string, n_sub + 1, sub_offsets, 0); - if (r != 0 && r != REG_NOMATCH) return - 1; + if (r != 0 && r != REG_NOMATCH) { + free(sub_offsets); + return - 1; + } regfree(&crx); - if (r == REG_NOMATCH) return 0; + if (r == REG_NOMATCH) { + free(sub_offsets); + return 0; + } va_start(va, n_sub); n = 1; @@ -62,7 +72,10 @@ match_rx(const char *rx, char *string, int n_sub, /* char **substrings */...) substring = va_arg(va, char**); if (substring != NULL) { - if (sub_offsets[n].rm_so == -1) return - 1; + if (sub_offsets[n].rm_so == -1) { + free(sub_offsets); + return - 1; + } *substring = string + sub_offsets[n].rm_so; *(string + sub_offsets[n].rm_eo) = 0; } diff --git a/anacron/runjob.c b/anacron/runjob.c index f045d00..13a0e87 100644 --- a/anacron/runjob.c +++ b/anacron/runjob.c @@ -64,8 +64,8 @@ temp_file(job_rec *jr) if (fdin == -1) die_e("Can't open temporary file for reading"); if (unlink(name)) die_e("Can't unlink temporary file"); free(name); - fcntl(fdout, F_SETFD, 1); /* set close-on-exec flag */ - fcntl(fdin, F_SETFD, 1); /* set close-on-exec flag */ + fcntl(fdout, F_SETFD, FD_CLOEXEC); /* set close-on-exec flag */ + fcntl(fdin, F_SETFD, FD_CLOEXEC); /* set close-on-exec flag */ jr->input_fd = fdin; jr->output_fd = fdout; @@ -175,8 +175,6 @@ launch_mailer(job_rec *jr) pid = xfork(); if (pid == 0) { - long fdflags; - /* child */ in_background = 1; /* set stdin to the job's output */