]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
mlmmj: fix resource leaks in dsnparseaddr()
authorMichael S. Tsirkin <mst@redhat.com>
Thu, 8 Jan 2026 12:41:26 +0000 (07:41 -0500)
committerBaptiste Daroussin <bapt@FreeBSD.org>
Fri, 13 Feb 2026 13:24:30 +0000 (14:24 +0100)
The dsnparseaddr() function has three resource leaks:

1. The file handle 'f' is never closed after parsing the DSN mail
2. The 'boundary' string is allocated but never freed
3. The 'emails' list is populated but never freed on exit

Free all three resources before all return paths.

Fixes: a1f1fbc8 ("mlmmj-bounce: make sure mlmmj-bounce is never called directly")
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
src/mlmmj.c

index a64a03681b4030bec48055ef75459377c4e9dc34..c88cf2713048339d09acd3515b69eb60669aa89b 100644 (file)
@@ -601,8 +601,10 @@ char *dsnparseaddr(const char *mailname)
                break;
        }
        /* this is not a miltipart/report mail see RFC1839 */
-       if (boundary == NULL)
+       if (boundary == NULL) {
+               fclose(f);
                return NULL;
+       }
        while ((getline(&buf, &bufcap, f) > 0)) {
                chomp(buf);
                if (indsn) {
@@ -646,6 +648,9 @@ char *dsnparseaddr(const char *mailname)
                }
        }
        free(buf);
+       free(boundary);
+       fclose(f);
+       tll_free_and_free(emails, free);
        return addr;
 }