]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: modernize match_make_string()
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Jan 2023 19:27:26 +0000 (20:27 +0100)
committerLennart Poettering <lennart@poettering.net>
Fri, 20 Jan 2023 20:46:32 +0000 (21:46 +0100)
src/libsystemd/sd-journal/sd-journal.c

index 204886b1e43d2dae289a1b19fbd189fb4c7b5164..ac8ca0f54b47a56e58de0d689b57d99c004cd725 100644 (file)
@@ -367,7 +367,7 @@ _public_ int sd_journal_add_disjunction(sd_journal *j) {
 }
 
 static char *match_make_string(Match *m) {
-        char *p = NULL, *r;
+        _cleanup_free_ char *p = NULL;
         bool enclose = false;
 
         if (!m)
@@ -377,34 +377,25 @@ static char *match_make_string(Match *m) {
                 return cescape_length(m->data, m->size);
 
         LIST_FOREACH(matches, i, m->matches) {
-                char *t, *k;
+                _cleanup_free_ char *t = NULL;
 
                 t = match_make_string(i);
                 if (!t)
-                        return mfree(p);
+                        return NULL;
 
                 if (p) {
-                        k = strjoin(p, m->type == MATCH_OR_TERM ? " OR " : " AND ", t);
-                        free(p);
-                        free(t);
-
-                        if (!k)
+                        if (!strextend(&p, m->type == MATCH_OR_TERM ? " OR " : " AND ", t))
                                 return NULL;
 
-                        p = k;
-
                         enclose = true;
                 } else
-                        p = t;
+                        p = TAKE_PTR(t);
         }
 
-        if (enclose) {
-                r = strjoin("(", p, ")");
-                free(p);
-                return r;
-        }
+        if (enclose)
+                return strjoin("(", p, ")");
 
-        return p;
+        return TAKE_PTR(p);
 }
 
 char *journal_make_match_string(sd_journal *j) {