From 654d98cbb4021b9fc0ecc888f6de1101adb75bb3 Mon Sep 17 00:00:00 2001 From: Daniel Spiljar Date: Fri, 10 Feb 2023 13:26:45 +0100 Subject: [PATCH 1/2] Fix multiple compilation errors and memory leaks. - Rename malloc_message() because it was causing a compilation error on FreeBSD. - Use correct type as a return from gzdopen(). - Memory allocation, header file includes, etc. --- src/maildir.c | 2 +- src/mbox.c | 2 +- src/mh.c | 2 +- src/misc.c | 2 +- src/misc.h | 2 +- src/re.c | 4 +++- src/wrap.c | 7 +++++-- src/wrap.h | 2 +- 8 files changed, 14 insertions(+), 9 deletions(-) diff --git a/src/maildir.c b/src/maildir.c index 65eb65e..4e7b608 100644 --- a/src/maildir.c +++ b/src/maildir.c @@ -122,7 +122,7 @@ maildir_read_message (maildir_t *mdp) static FILE *fp; static int s; - message = malloc_message (); + message = allocate_message (); for(;;) { diff --git a/src/mbox.c b/src/mbox.c index 15cf9c5..1cbf57e 100644 --- a/src/mbox.c +++ b/src/mbox.c @@ -237,7 +237,7 @@ mbox_read_message (mbox_t * mp) char buffer[BUFSIZ]; message_t *message; - message = malloc_message (); + message = allocate_message (); s = strlen (mp->postmark_cache); message->headers = diff --git a/src/mh.c b/src/mh.c index c5f4143..abf4bb2 100644 --- a/src/mh.c +++ b/src/mh.c @@ -87,7 +87,7 @@ message_t *mh_read_message (DIR *dp) char buffer[BUFSIZ], *filename; FILE *fp; - message = malloc_message (); + message = allocate_message (); filename = NULL; diff --git a/src/misc.c b/src/misc.c index f1e5c05..4d5bc85 100644 --- a/src/misc.c +++ b/src/misc.c @@ -139,7 +139,7 @@ char * parse_return_path(char *rpath) } /* }}} */ -void * malloc_message (void) +void * allocate_message (void) { message_t *message; diff --git a/src/misc.h b/src/misc.h index 02ddd92..209bdca 100644 --- a/src/misc.h +++ b/src/misc.h @@ -29,7 +29,7 @@ format_t folder_format (const char *name); lockmethod_t lock_method (const char *name); /* time_t parse_date(char *datestr); */ char * parse_return_path(char *rpath); -void * malloc_message (void); +void * allocate_message (void); void postmark_print (message_t *msg); void set_default_options (void); void get_runtime_options (int *argc, char **argv, struct option *long_options); diff --git a/src/re.c b/src/re.c index 9c985a3..2d6e95a 100644 --- a/src/re.c +++ b/src/re.c @@ -26,6 +26,7 @@ #endif /* HAVE_LIBPCRE */ #include "mboxgrep.h" #include "message.h" +#include "wrap.h" /* xcalloc() et cetera */ #ifdef HAVE_LIBPCRE void @@ -81,7 +82,8 @@ regex_init (void) flag1 = REG_ICASE; if (config.extended) flag2 = REG_EXTENDED; - + + config.posix_pattern = (regex_t *) xmalloc (sizeof (regex_t)); errcode = regcomp ((regex_t *) config.posix_pattern, config.regex_s, (flag1 | flag2 | REG_NEWLINE )); if (0 != errcode) diff --git a/src/wrap.c b/src/wrap.c index f08e3fd..a5ec960 100644 --- a/src/wrap.c +++ b/src/wrap.c @@ -42,6 +42,9 @@ #ifdef HAVE_LIBZ #include #endif /* HAVE_LIBZ */ +#ifdef HAVE_LIBBZ2 +#include +#endif /* HAVE_LIBBZ2 */ #include #include @@ -108,9 +111,9 @@ FILE *m_fdopen (int fildes, const char *mode) #ifdef HAVE_LIBZ -gzFile *m_gzdopen (int fildes, const char *mode) +gzFile m_gzdopen (int fildes, const char *mode) { - gzFile *blah; + gzFile blah; blah = gzdopen (fildes, mode); if (blah == NULL) diff --git a/src/wrap.h b/src/wrap.h index 6b97e7d..4fd64d5 100644 --- a/src/wrap.h +++ b/src/wrap.h @@ -56,7 +56,7 @@ int m_open (const char *pathname, int flags, mode_t mode); FILE *m_fopen (const char *path, const char *mode); FILE *m_fdopen (int fildes, const char *mode); #ifdef HAVE_LIBZ -gzFile *m_gzdopen (int fildes, const char *mode); +gzFile m_gzdopen (int fildes, const char *mode); void gzwrite_loop (void *fp, char *str); #endif /* HAVE_LIBZ */ #ifdef HAVE_LIBBZ2 From f7bdabb29da200bc054fc7279d932d316b04fb6a Mon Sep 17 00:00:00 2001 From: Daniel Spiljar Date: Fri, 10 Feb 2023 17:23:28 +0100 Subject: [PATCH 2/2] Fix a call of fprintf(). --- src/info.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/info.c b/src/info.c index 68c359a..4dc1022 100644 --- a/src/info.c +++ b/src/info.c @@ -30,7 +30,7 @@ void print_wrap (char *str, int len, int *n) { *n += len; - fprintf (stdout, str); + fprintf (stdout, "%s", str); if (*n >= 50) { fprintf (stdout, "\n");