]> git.ipfire.org Git - thirdparty/mlmmj.git/commitdiff
subscriberfuncs: fix memory leak in autosubscribe_sender
authorMichael S. Tsirkin <mst@redhat.com>
Wed, 7 Jan 2026 08:42:53 +0000 (03:42 -0500)
committerMichael S. Tsirkin <mst@redhat.com>
Wed, 7 Jan 2026 12:51:55 +0000 (07:51 -0500)
The readhdrs structure allocated by scan_headers() was never freed,
causing a memory leak on every call to autosubscribe_sender(). Add
free_mailhdrs() calls to all return paths.

Fixes: ac7f764 ("autosubscribe: new feature")
src/subscriberfuncs.c

index 791ae74687b26e8617f9910609df61fa36ea8250..618e392196568a45c80ac542447dc804e5f105d6 100644 (file)
@@ -736,18 +736,23 @@ autosubscribe_sender(struct ml *ml, int mailfd, enum subtype typesub)
        FILE *f = fdopen(mailfd, "r");
        scan_headers(f, readhdrs, NULL, NULL);
        fclose(f);
-       if (readhdrs[0].valuecount == 0)
+       if (readhdrs[0].valuecount == 0) {
+               free_mailhdrs(readhdrs);
                return;
+       }
        find_email_adr(readhdrs[0].values[0], &from);
        if (tll_length(from) == 0) {
                tll_free(from);
+               free_mailhdrs(readhdrs);
                return;
        }
        if (strchr(tll_front(from), '@') == NULL) {
                tll_free_and_free(from, free);
+               free_mailhdrs(readhdrs);
                return;
        }
        subscribe_type(ml->fd, tll_front(from), typesub);
        tll_free_and_free(from, free);
+       free_mailhdrs(readhdrs);
 }