From 8bd72ff8b3c9b59b3800042782a3fd28a65abddc Mon Sep 17 00:00:00 2001 From: Andre Noll Date: Tue, 26 Nov 2024 00:28:53 +0100 Subject: [PATCH] Fix memory leak in playlist.c. 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 | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/playlist.c b/playlist.c index c145b0fd..0a246244 100644 --- a/playlist.c +++ b/playlist.c @@ -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); -- 2.39.5