]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mood.c: Fix memory leak in error path of load_mood().
authorAndre Noll <maan@tuebingen.mpg.de>
Thu, 10 Mar 2022 20:32:22 +0000 (21:32 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 12 Mar 2022 16:06:51 +0000 (17:06 +0100)
When an existing mood definition happens to be invalid so that
mp_init() fails, we return negative and leak the mood structure
just allocated.

This bug was introduced by the commit which removed version 1 moods.
It was found by code inspection.

Fixes: 184ea897a9b4
mood.c

diff --git a/mood.c b/mood.c
index e0d9e2750dd65b53f988e9b7ff06b981300cc31f..fbc22297fd0df3a2d1fb5b7927fde5b1a7825315 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -163,6 +163,8 @@ static int load_mood(const struct osl_row *mood_row, struct mood **m,
        PARA_INFO_LOG("opening mood %s\n", mood_name);
        ret = mp_init(mood_def.data, mood_def.size, &(*m)->parser_context, errmsg);
        osl_close_disk_object(&mood_def);
+       if (ret < 0)
+               destroy_mood(*m);
        return ret;
 }