]> git.tuebingen.mpg.de Git - paraslash.git/commitdiff
afs: Fix memory leak in mood_load().
authorAndre Noll <maan@tuebingen.mpg.de>
Sun, 7 May 2023 18:04:19 +0000 (20:04 +0200)
committerAndre Noll <maan@tuebingen.mpg.de>
Fri, 12 May 2023 10:19:34 +0000 (12:19 +0200)
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

diff --git a/mood.c b/mood.c
index 9cdfd011a6ef4f2ab9fb180892f6412247eb68fe..e85cf36a35b9e533370bddd95c5c5db74a214e85 100644 (file)
--- 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;
 }