From 6e3e710015b0b2c208b80a91d5f7842482359db2 Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Sun, 7 May 2023 20:04:19 +0200 Subject: [PATCH] afs: Fix memory leak in mood_load(). If mood_load() manages to load the mood but does not find any admissible files, it does not deallocate the mood instance and does not set up the global current_mood variable either. Plug the resulting memory leak by destroying the mood also if there are no admissible files (ret == 0). --- mood.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mood.c b/mood.c index 9cdfd011..e85cf36a 100644 --- a/mood.c +++ b/mood.c @@ -630,9 +630,10 @@ int mood_load(const char *mood_name, char **msg) ret = aa.m->stats.num; mood_unload(); current_mood = aa.m; + ret = 1; out: free(aa.array); - if (ret < 0) + if (ret <= 0) /* error, or no admissible files */ destroy_mood(aa.m); return ret; } -- 2.39.5