From 74ebbb6021658753927e4ff2c206da719dd12032 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 8 Mar 2022 23:37:08 +0100 Subject: [PATCH] mood.c: Fix memory leak in change_current_mood(). 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 | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/mood.c b/mood.c index d6a82923..4e0a7e3d 100644 --- 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; } -- 2.39.2