[vlc-commits] kva: fix double free on error, and remove useless struct member

Rémi Denis-Courmont git at videolan.org
Sun Jul 14 18:33:00 CEST 2013


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sun Jul 14 19:31:02 2013 +0300| [81b4850d87aae326135f62e00c91e6f6a99d1e0d] | committer: Rémi Denis-Courmont

kva: fix double free on error, and remove useless struct member

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=81b4850d87aae326135f62e00c91e6f6a99d1e0d
---

 modules/video_output/kva.c |   32 ++++++++++----------------------
 1 file changed, 10 insertions(+), 22 deletions(-)

diff --git a/modules/video_output/kva.c b/modules/video_output/kva.c
index eaca5e3..9b149db 100644
--- a/modules/video_output/kva.c
+++ b/modules/video_output/kva.c
@@ -101,7 +101,6 @@ struct vout_display_sys_t
     HWND               parent;
     RECTL              parent_rect;
     picture_pool_t    *pool;
-    picture_resource_t resource;
     unsigned           button_pressed;
     bool               is_mouse_hidden;
     bool               is_on_top;
@@ -657,24 +656,19 @@ static int OpenDisplay( vout_display_t *vd, video_format_t *fmt )
     }
 
     /* Create the associated picture */
-    picture_resource_t *rsc = &sys->resource;
-    rsc->p_sys = malloc( sizeof( *rsc->p_sys ));
-    if( !rsc->p_sys )
-        return VLC_EGENERIC;
-
-    rsc->p_sys->i_chroma_shift = i_chroma_shift;
+    picture_sys_t *picsys = malloc( sizeof( *picsys ) );
+    if( picsys == NULL )
+        return VLC_ENOMEM;
+    picsys->i_chroma_shift = i_chroma_shift;
 
-    for( int i = 0; i < PICTURE_PLANE_MAX; i++ )
+    picture_resource_t resource = { .p_sys = picsys };
+    picture_t *picture = picture_NewFromResource( fmt, &resource );
+    if( !picture )
     {
-        rsc->p[ i ].p_pixels = NULL;
-        rsc->p[ i ].i_pitch  = 0;
-        rsc->p[ i ].i_lines  = 0;
+        free( picsys );
+        return VLC_ENOMEM;
     }
 
-    picture_t *picture = picture_NewFromResource( fmt, rsc );
-    if( !picture )
-        goto exit_picture;
-
     /* Wrap it into a picture pool */
     picture_pool_configuration_t pool_cfg;
     memset( &pool_cfg, 0, sizeof( pool_cfg ));
@@ -687,8 +681,7 @@ static int OpenDisplay( vout_display_t *vd, video_format_t *fmt )
     if( !sys->pool )
     {
         picture_Release( picture );
-
-        goto exit_picture;
+        return VLC_ENOMEM;
     }
 
     if (vd->cfg->display.title)
@@ -726,11 +719,6 @@ static int OpenDisplay( vout_display_t *vd, video_format_t *fmt )
                      SWP_ACTIVATE );
 
     return VLC_SUCCESS;
-
-exit_picture:
-    free( rsc->p_sys );
-
-    return VLC_EGENERIC;
 }
 
 /*****************************************************************************



More information about the vlc-commits mailing list