[vlc-devel] [PATCH 02/12] medialibrary: Zero initialize all fields before converting

Hugo Beauzée-Luyssen hugo at beauzee.fr
Wed Jul 31 11:20:31 CEST 2019


---
 modules/misc/medialibrary/medialib.cpp   | 4 ++--
 modules/misc/medialibrary/medialibrary.h | 4 ++--
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/modules/misc/medialibrary/medialib.cpp b/modules/misc/medialibrary/medialib.cpp
index a2620b7cea..e4bc4da85f 100644
--- a/modules/misc/medialibrary/medialib.cpp
+++ b/modules/misc/medialibrary/medialib.cpp
@@ -89,7 +89,7 @@ void wrapEntityEventCallback( vlc_medialibrary_module_t* ml,
     ev.i_type = evType;
     for ( const auto& e : entities )
     {
-        auto val = vlc::wrap_cptr<To>( static_cast<To*>( malloc( sizeof( To ) ) ),
+        auto val = vlc::wrap_cptr<To>( static_cast<To*>( calloc( 1, sizeof( To ) ) ),
                                        static_cast<void(*)(To*)>( vlc_ml_release ) );
         if ( unlikely( val == nullptr ) )
             return;
@@ -292,7 +292,7 @@ void MediaLibrary::onMediaThumbnailReady( medialibrary::MediaPtr media,
     ev.media_thumbnail_generated.b_success = success;
     ev.media_thumbnail_generated.i_size = static_cast<vlc_ml_thumbnail_size_t>( sizeType );
     auto mPtr = vlc::wrap_cptr<vlc_ml_media_t>(
-                static_cast<vlc_ml_media_t*>( malloc( sizeof( vlc_ml_media_t ) ) ),
+                static_cast<vlc_ml_media_t*>( calloc( 1, sizeof( vlc_ml_media_t ) ) ),
                 vlc_ml_media_release );
     if ( unlikely( mPtr == nullptr ) )
         return;
diff --git a/modules/misc/medialibrary/medialibrary.h b/modules/misc/medialibrary/medialibrary.h
index 1380d2f95a..ccab3e0d84 100644
--- a/modules/misc/medialibrary/medialibrary.h
+++ b/modules/misc/medialibrary/medialibrary.h
@@ -224,7 +224,7 @@ To* ml_convert_list( const std::vector<std::shared_ptr<From>>& input )
 
     // Allocate the ml_*_list_t
     auto list = vlc::wrap_cptr(
-        static_cast<To*>( malloc( sizeof( To ) + input.size() * sizeof( ItemType ) ) ),
+        static_cast<To*>( calloc( 1, sizeof( To ) + input.size() * sizeof( ItemType ) ) ),
         static_cast<void(*)(To*)>( &vlc_ml_release ) );
     if ( unlikely( list == nullptr ) )
         return nullptr;
@@ -246,7 +246,7 @@ T* CreateAndConvert( const Input* input )
     if ( input == nullptr )
         return nullptr;
     auto res = vlc::wrap_cptr(
-                static_cast<T*>( malloc( sizeof( T ) ) ),
+                static_cast<T*>( calloc( 1, sizeof( T ) ) ),
                 static_cast<void(*)(T*)>( &vlc_ml_release ) );
     if ( unlikely( res == nullptr ) )
         return nullptr;
-- 
2.20.1



More information about the vlc-devel mailing list