[vlc-devel] [PATCH v3 07/12] picture: always initialize picture_priv_t to 0

Steve Lhomme robux4 at ycbcr.xyz
Tue Aug 18 08:24:48 CEST 2020


No need to allocate and memset afterwards.
---
 src/misc/picture.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/misc/picture.c b/src/misc/picture.c
index 009bb38b75a..ecb15611d1d 100644
--- a/src/misc/picture.c
+++ b/src/misc/picture.c
@@ -202,7 +202,6 @@ static bool picture_InitPrivate(const video_format_t *restrict p_fmt,
 {
     picture_t *p_picture = &priv->picture;
 
-    memset( p_picture, 0, sizeof( *p_picture ) );
     p_picture->date = VLC_TICK_INVALID;
 
     p_picture->format = *p_fmt;
@@ -211,7 +210,6 @@ static bool picture_InitPrivate(const video_format_t *restrict p_fmt,
         return false;
 
     atomic_init(&p_picture->refs, 1);
-    priv->gc.opaque = NULL;
 
     if ( p_resource == NULL)
         priv->gc.destroy = picture_DestroyDummy;
@@ -227,7 +225,7 @@ static bool picture_InitPrivate(const video_format_t *restrict p_fmt,
 
 picture_t *picture_NewFromResource( const video_format_t *p_fmt, const picture_resource_t *p_resource )
 {
-    picture_priv_t *priv = malloc(sizeof(*priv));
+    picture_priv_t *priv = calloc(1, sizeof(*priv));
     if (unlikely(priv == NULL))
         return NULL;
 
@@ -252,7 +250,7 @@ picture_t *picture_NewFromFormat(const video_format_t *restrict fmt)
     static_assert(offsetof(struct picture_priv_buffer_t, priv)==0,
                   "misplaced picture_priv_t, destroy won't work");
 
-    struct picture_priv_buffer_t *privbuf = malloc(sizeof(*privbuf));
+    struct picture_priv_buffer_t *privbuf = calloc(1, sizeof(*privbuf));
     if (unlikely(privbuf == NULL))
         return NULL;
 
-- 
2.26.2



More information about the vlc-devel mailing list