From ac3d5133dafb6ce42ecddd42de4a59bd93e06d45 Mon Sep 17 00:00:00 2001 From: Matthias Andree Date: Fri, 6 Mar 2020 16:47:56 +0100 Subject: Plug memory leak when merging/overriding options... ...from defaults entries, or command line. --- fetchmail.c | 69 +++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 29 deletions(-) (limited to 'fetchmail.c') diff --git a/fetchmail.c b/fetchmail.c index c44d85fe..376e6e6b 100644 --- a/fetchmail.c +++ b/fetchmail.c @@ -966,42 +966,45 @@ static void optmerge(struct query *h2, struct query *h1, int force) list_merge(&h2->antispam, &h1->antispam, force); #define FLAG_MERGE(fld) do { if (force ? !!h1->fld : !h2->fld) h2->fld = h1->fld; } while (0) - FLAG_MERGE(server.via); +#define STRING_MERGE(fld) do { if (force ? !!h1->fld : !h2->fld) { if (h2->fld) free((void *)h2->fld); h2->fld = h1->fld; } } while (0) + STRING_MERGE(server.via); FLAG_MERGE(server.protocol); - FLAG_MERGE(server.service); + STRING_MERGE(server.service); FLAG_MERGE(server.interval); FLAG_MERGE(server.authenticate); FLAG_MERGE(server.timeout); - FLAG_MERGE(server.envelope); + STRING_MERGE(server.envelope); FLAG_MERGE(server.envskip); - FLAG_MERGE(server.qvirtual); + STRING_MERGE(server.qvirtual); FLAG_MERGE(server.skip); FLAG_MERGE(server.dns); FLAG_MERGE(server.checkalias); FLAG_MERGE(server.uidl); - FLAG_MERGE(server.principal); + STRING_MERGE(server.principal); + STRING_MERGE(server.esmtp_name); + STRING_MERGE(server.esmtp_password); #ifdef CAN_MONITOR - FLAG_MERGE(server.interface); - FLAG_MERGE(server.interface_pair); - FLAG_MERGE(server.monitor); + STRING_MERGE(server.interface); + FLAG_MERGE(server.interface_pair); /* XXX FIXME: leaky? */ + STRING_MERGE(server.monitor); #endif - FLAG_MERGE(server.plugin); - FLAG_MERGE(server.plugout); + STRING_MERGE(server.plugin); + STRING_MERGE(server.plugout); FLAG_MERGE(server.tracepolls); FLAG_MERGE(server.badheader); FLAG_MERGE(wildcard); - FLAG_MERGE(remotename); - FLAG_MERGE(password); - FLAG_MERGE(mda); - FLAG_MERGE(bsmtp); + STRING_MERGE(remotename); + STRING_MERGE(password); + STRING_MERGE(mda); + STRING_MERGE(bsmtp); FLAG_MERGE(listener); - FLAG_MERGE(smtpaddress); - FLAG_MERGE(smtpname); - FLAG_MERGE(preconnect); - FLAG_MERGE(postconnect); + STRING_MERGE(smtpaddress); + STRING_MERGE(smtpname); + STRING_MERGE(preconnect); + STRING_MERGE(postconnect); FLAG_MERGE(keep); FLAG_MERGE(flush); @@ -1023,14 +1026,14 @@ static void optmerge(struct query *h2, struct query *h1, int force) FLAG_MERGE(batchlimit); #ifdef SSL_ENABLE FLAG_MERGE(use_ssl); - FLAG_MERGE(sslkey); - FLAG_MERGE(sslcert); - FLAG_MERGE(sslproto); + STRING_MERGE(sslkey); + STRING_MERGE(sslcert); + STRING_MERGE(sslproto); FLAG_MERGE(sslcertck); - FLAG_MERGE(sslcertfile); - FLAG_MERGE(sslcertpath); - FLAG_MERGE(sslcommonname); - FLAG_MERGE(sslfingerprint); + STRING_MERGE(sslcertfile); + STRING_MERGE(sslcertpath); + STRING_MERGE(sslcommonname); + STRING_MERGE(sslfingerprint); #endif FLAG_MERGE(expunge); @@ -1169,12 +1172,18 @@ static int load_params(int argc, char **argv, int optind) fetchmailhost = "localhost"; /* here's where we override globals */ - if (cmd_run.logfile) + if (cmd_run.logfile) { + xfree(run.logfile); run.logfile = cmd_run.logfile; - if (cmd_run.idfile) + } + if (cmd_run.idfile) { + xfree(run.idfile); run.idfile = cmd_run.idfile; - if (cmd_run.pidfile) + } + if (cmd_run.pidfile) { + xfree(run.pidfile); run.pidfile = cmd_run.pidfile; + } /* do this before the keep/fetchall test below, otherwise -d0 may fail */ if (cmd_run.poll_interval >= 0) run.poll_interval = cmd_run.poll_interval; @@ -1184,8 +1193,10 @@ static int load_params(int argc, char **argv, int optind) run.showdots = (cmd_run.showdots == FLAG_TRUE); if (cmd_run.use_syslog) run.use_syslog = (cmd_run.use_syslog == FLAG_TRUE); - if (cmd_run.postmaster) + if (cmd_run.postmaster) { + free((void *)run.postmaster); run.postmaster = cmd_run.postmaster; + } if (cmd_run.bouncemail) run.bouncemail = (cmd_run.bouncemail == FLAG_TRUE); if (cmd_run.softbounce) -- cgit v1.2.3