[vlc-devel] [PATCH 3/3] lib: media: Hold the media during the preparsing

Hugo Beauzée-Luyssen hugo at beauzee.fr
Fri Nov 13 14:07:04 CET 2020


This prevents a potential use after free if the caller releases the
media before the preparsing is complete, or if the media is immediatly
released after the preparsing completes since
a4a94bb3f942989302d0aebc22f3de8ad897a8ff
---
 lib/media.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/media.c b/lib/media.c
index 7ab98de7c1..346809f93b 100644
--- a/lib/media.c
+++ b/lib/media.c
@@ -404,6 +404,7 @@ static void input_item_preparse_ended(input_item_t *item,
             return;
     }
     send_parsed_changed( p_md, new_status );
+    libvlc_media_release( p_md );
 }
 
 /**
@@ -835,11 +836,15 @@ static int media_parse(libvlc_media_t *media, bool b_async,
         if (parse_flag & libvlc_media_do_interact)
             parse_scope |= META_REQUEST_OPTION_DO_INTERACT;
 
+        libvlc_media_retain(media);
         ret = libvlc_MetadataRequest(libvlc, item, parse_scope,
                                      &input_preparser_callbacks, media,
                                      timeout, media);
         if (ret != VLC_SUCCESS)
+        {
+            libvlc_media_release(media);
             return ret;
+        }
     }
     else
         return VLC_EGENERIC;
-- 
2.29.2



More information about the vlc-devel mailing list