]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
mood.c: Fix memory leak in change_current_mood().
authorAndre Noll <maan@tuebingen.mpg.de>
Tue, 8 Mar 2022 22:37:08 +0000 (23:37 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Sat, 12 Mar 2022 15:47:16 +0000 (16:47 +0100)
In two error cases we return without freeing the bison mood parser
and the temporary array. Worse, in these cases we also expose the
partially loaded mood via the global current_mood.

The good news is that these errors should be "impossible" to trigger
in practice.

mood.c

diff --git a/mood.c b/mood.c
index d6a8292340aba7f48fb7816f96d9e9c0f672f210..4e0a7e3ddca78ed0e274cd2afba792fe767e25c3 100644 (file)
--- a/mood.c
+++ b/mood.c
@@ -903,7 +903,7 @@ int change_current_mood(const char *mood_name, char **errmsg)
        if (ret < 0) {
                if (errmsg)
                        *errmsg = make_message("audio file loop failed");
-               return ret;
+               goto out;
        }
        for (i = 0; i < statistics.num; i++) {
                struct admissible_file_info *a = aa.array + i;
@@ -919,6 +919,8 @@ int change_current_mood(const char *mood_name, char **errmsg)
        ret = statistics.num;
 out:
        free(aa.array);
+       if (ret < 0)
+               close_current_mood();
        return ret;
 }