[vlc-devel] [PATCH 7/7] player: Fix memory leak on error path

Hugo Beauzée-Luyssen hugo at beauzee.fr
Tue Jan 21 16:18:04 CET 2020


---
 src/player/medialib.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/src/player/medialib.c b/src/player/medialib.c
index d9b70fac55..02249f41ea 100644
--- a/src/player/medialib.c
+++ b/src/player/medialib.c
@@ -44,10 +44,17 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
         return;
     input_item_t* item = input_GetItem(input->thread);
     vlc_ml_media_t* media = vlc_ml_get_media_by_mrl( ml, item->psz_uri);
-    if (!media || media->i_type != VLC_ML_MEDIA_TYPE_VIDEO)
+    if (!media)
         return;
-    if (vlc_ml_media_get_all_playback_pref(ml, media->i_id, &input->ml.states) != VLC_SUCCESS)
+    if (media->i_type != VLC_ML_MEDIA_TYPE_VIDEO ||
+        vlc_ml_media_get_all_playback_pref(ml, media->i_id,
+                                           &input->ml.states) != VLC_SUCCESS)
+    {
+        vlc_ml_release(media);
         return;
+    }
+    vlc_ml_release(media);
+
     input->ml.restore = (restore_pos == VLC_PLAYER_RESTORE_PLAYBACK_POS_ALWAYS) ?
                             VLC_RESTOREPOINT_TITLE : VLC_RESTOREPOINT_NONE;
     input->ml.restore_states = restore_states;
@@ -124,7 +131,6 @@ vlc_player_input_RestoreMlStates(struct vlc_player_input* input, bool force_pos)
             var_SetString(vout, "video-filter", NULL);
         vout_Release(vout);
     }
-    vlc_ml_release(media);
 }
 
 static const float beginning_of_media_percent = .5f;
-- 
2.20.1



More information about the vlc-devel mailing list