From d91e3439091d4909a01f0310b88991a5b2511f42 Mon Sep 17 00:00:00 2001
From: Romain Vimont <rom1v@videolabs.io>
Date: Mon, 22 Nov 2021 16:29:14 +0100
Subject: [PATCH] mtp: fix leak on error

---
 modules/services_discovery/mtp.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/modules/services_discovery/mtp.c b/modules/services_discovery/mtp.c
index 90d2bdfd8821..c28f9d63b151 100644
--- a/modules/services_discovery/mtp.c
+++ b/modules/services_discovery/mtp.c
@@ -219,6 +219,12 @@ static int AddDevice( services_discovery_t *p_sd,
                                                    sizeof( input_item_t * ) ) ) )
             {
                 free( psz_name );
+                while ( p_track ) {
+                    p_tmp = p_track;
+                    p_track = p_track->next;
+                    LIBMTP_destroy_track_t( p_tmp );
+                }
+                LIBMTP_Release_Device( p_device );
                 return VLC_ENOMEM;
             }
             p_sys->i_count = 0;
-- 
GitLab