]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
send_mail: fix memory leak in newsmtp()
authorMichael S. Tsirkin <mst@redhat.com>
Thu, 8 Jan 2026 12:34:40 +0000 (07:34 -0500)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 13 Feb 2026 13:23:20 +0000 (14:23 +0100)
The newsmtp() function allocates memory for relayhost and smtphelo
but never frees them.

- relayhost: allocated via xstrdup() or ctrlvalue()
- smtphelo: allocated via ctrlvalue() or hostnamestr()

Both allocations are only used temporarily to call initsmtp(), which
copies the values it needs. So, just free() both.

Fixes: 48418b61 ("mlmmj-bounce: use send_mail directly and stop executing mlmmj-send")
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
src/send_mail.c

index a83b086772b0fc893181b08fa2dac187f0aa02aa..948aa98483b0b5369e6903a263dd4920aa50d39d 100644 (file)
@@ -367,8 +367,13 @@ newsmtp(struct ml *ml, const char *rhost)
        smtphelo = ctrlvalue(ml->ctrlfd, "smtphelo");
        if (smtphelo == NULL)
                smtphelo = hostnamestr();
-       if (initsmtp(&sockfd, relayhost, smtpport, smtphelo) != 0)
+       if (initsmtp(&sockfd, relayhost, smtpport, smtphelo) != 0) {
+               free(relayhost);
+               free(smtphelo);
                return (-1);
+       }
+       free(relayhost);
+       free(smtphelo);
        return (sockfd);
 }