]> git.tue.mpg.de Git - paraslash.git/commitdiff
Fix memory leak in playlist.c.
authorAndre Noll <maan@tuebingen.mpg.de>
Mon, 25 Nov 2024 23:28:53 +0000 (00:28 +0100)
committerAndre Noll <maan@tuebingen.mpg.de>
Wed, 25 Dec 2024 20:08:32 +0000 (21:08 +0100)
If the result pointer is NULL. we currently leak one playlist instance
structure (12 bytes on 32 bit, 20 bytes on 64 bit) each time a playlist
is loaded.

Found by valgrind.

Fixes: 2d2637cb4c9ab76fea6bc336b9af88fd00bf5e08
playlist.c

index c145b0fd80ce0520bda58f0949c46211eeee5fdd..0a246244df5824ce60b0ea2f3110a0e0f9bc4db9 100644 (file)
@@ -176,13 +176,14 @@ int playlist_load(const char *name, struct playlist_instance **result, char **ms
                *msg = make_message("loaded playlist %s (%u files)\n", name,
                        pi->length);
        pi->name = para_strdup(name);
-       if (result)
+       if (result) {
                *result = pi;
-       else {
-               playlist_unload(NULL);
-               current_playlist = *pi;
+               return pi->length;
        }
-       return pi->length;
+       playlist_unload(NULL);
+       current_playlist = *pi;
+       free(pi);
+       return current_playlist.length;
 close_score_table:
        if (result)
                score_close(pi->score_table);