From: Baptiste Daroussin Date: Wed, 8 Feb 2023 15:58:25 +0000 (+0100) Subject: mlmmj-process: reduce memory allocation X-Git-Tag: RELEASE_1_4_0b1~227 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bdfbda866ee403d37a196f20d0d8db83ff06a061;p=thirdparty%2Fmlmmj.git mlmmj-process: reduce memory allocation When matching the mailing lists, addrmatch extracts the extra part of the recipient. only allocate memory for it if there is actually something there. --- diff --git a/src/utils.c b/src/utils.c index 87f64a23..1f4c245d 100644 --- a/src/utils.c +++ b/src/utils.c @@ -273,7 +273,8 @@ addrmatch(const char *listaddr, const char *addr, if (recipextra) { len = atsign - delim; - *recipextra = xstrndup(delim, len); + if (len > 0) + *recipextra = xstrndup(delim, len); } return (true); diff --git a/tests/mlmmj.c b/tests/mlmmj.c index 96fc8933..281cc93a 100644 --- a/tests/mlmmj.c +++ b/tests/mlmmj.c @@ -2049,7 +2049,7 @@ ATF_TC_BODY(addrmatch, tc) ATF_REQUIRE(!addrmatch("lists@test.org", "nope@test.org", "+", &extra)); ATF_REQUIRE(!addrmatch("lists@test.org", "nope@test.org", NULL, &extra)); ATF_REQUIRE(addrmatch("lists@test.org", "lists+@test.org", "+", &extra)); - ATF_REQUIRE_STREQ(extra, ""); + ATF_REQUIRE(extra == NULL); ATF_REQUIRE(!addrmatch("lists@test.org", "list+@test.org", "+", &extra)); ATF_REQUIRE(!addrmatch("lists@test.org", "lists+@bla.org", "+", &extra)); ATF_REQUIRE(!addrmatch("lists@test.org", "bla+@test.org", "+", &extra));