1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2025-01-03 01:17:45 +03:00

Merge pull request #21869 from yuwata/sd-journal-fix-segfault

sd-journal: fix segfault
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2021-12-23 20:07:41 +01:00 committed by GitHub
commit 10c8c32f13
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -212,7 +212,7 @@ static Match *match_new(Match *p, MatchType t) {
return m;
}
static void match_free(Match *m) {
static Match *match_free(Match *m) {
assert(m);
while (m->matches)
@ -222,18 +222,18 @@ static void match_free(Match *m) {
LIST_REMOVE(matches, m->parent->matches, m);
free(m->data);
free(m);
return mfree(m);
}
static void match_free_if_empty(Match *m) {
static Match *match_free_if_empty(Match *m) {
if (!m || m->matches)
return;
return m;
match_free(m);
return match_free(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);
@ -322,10 +322,11 @@ _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);
match_free_if_empty(j->level0);
j->level2 = match_free_if_empty(j->level2);
j->level1 = match_free_if_empty(j->level1);
j->level0 = match_free_if_empty(j->level0);
return -ENOMEM;
}