From cd9b726453398bef20c66f30a454eb503f7bcb72 Mon Sep 17 00:00:00 2001
From: Yu Watanabe <watanabe.yu+github@gmail.com>
Date: Thu, 23 Dec 2021 21:35:29 +0900
Subject: [PATCH] sd-journal: free incomplete match on failure

(cherry picked from commit 418cce628cf28d4feaeda60241cf9781f8afbf1c)

Conflict:NA
Reference:https://github.com/systemd/systemd/commit/cd9b726453398bef20c66f30a454eb503f7bcb72
---
 src/libsystemd/sd-journal/sd-journal.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c
index 71875a4dc8..63b8f0dc7b 100644
--- a/src/libsystemd/sd-journal/sd-journal.c
+++ b/src/libsystemd/sd-journal/sd-journal.c
@@ -232,7 +232,7 @@ static void match_free_if_empty(Match *m) {
 }
 
 _public_ int sd_journal_add_match(sd_journal *j, const void *data, size_t size) {
-        Match *l3, *l4, *add_here = NULL, *m;
+        Match *l3, *l4, *add_here = NULL, *m = NULL;
         uint64_t hash;
 
         assert_return(j, -EINVAL);
@@ -321,6 +321,7 @@ _public_ int sd_journal_add_match(sd_journal *j, const void *data, size_t size)
         return 0;
 
 fail:
+        match_free(m);
         match_free_if_empty(add_here);
         match_free_if_empty(j->level2);
         match_free_if_empty(j->level1);
-- 
2.33.0

