From b3331ee49b11ccd4e3e0a8ab592ac702103af81e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hugo=20Beauz=C3=A9e-Luyssen?= Date: Tue, 2 Jan 2018 14:14:14 +0100 Subject: [PATCH] media_player: Fix leaks in get_full_chapter_descriptions() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit e0f8269e445c5822ce6d05e2654847cba6a305e0) Signed-off-by: Hugo Beauzée-Luyssen --- lib/media_player.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/media_player.c b/lib/media_player.c index 3d159f7123..79956e0963 100644 --- a/lib/media_player.c +++ b/lib/media_player.c @@ -1599,7 +1599,7 @@ int libvlc_media_player_get_full_chapter_descriptions( libvlc_media_player_t *p_ *pp_chapters = calloc( ci_chapter_count, sizeof(**pp_chapters) ); if( !*pp_chapters ) { - return -1; + goto error; } /* fill array */ @@ -1608,8 +1608,7 @@ int libvlc_media_player_get_full_chapter_descriptions( libvlc_media_player_t *p_ libvlc_chapter_description_t *p_chapter = malloc( sizeof(*p_chapter) ); if( unlikely(p_chapter == NULL) ) { - libvlc_chapter_descriptions_release( *pp_chapters, ci_chapter_count ); - return -1; + goto error; } (*pp_chapters)[i] = p_chapter; @@ -1633,9 +1632,19 @@ int libvlc_media_player_get_full_chapter_descriptions( libvlc_media_player_t *p_ p_chapter->psz_name = NULL; } vlc_seekpoint_Delete( p_seekpoint[i] ); + p_seekpoint[i] = NULL; } + free( p_seekpoint ); return ci_chapter_count; + +error: + if( *pp_chapters ) + libvlc_chapter_descriptions_release( *pp_chapters, ci_chapter_count ); + for ( int i = 0; i < ci_chapter_count; ++i ) + vlc_seekpoint_Delete( p_seekpoint[i] ); + free( p_seekpoint ); + return -1; } void libvlc_chapter_descriptions_release( libvlc_chapter_description_t **p_chapters,