]> git.sesse.net Git - vlc/blobdiff - src/video_output/video_output.c
Partially fix data leaks when vout creation fails.
[vlc] / src / video_output / video_output.c
index d2be65a4a8ea1db608b2f06ee09c00f5d0443ee5..44015d506982214ff27f053757388e43e1952358 100644 (file)
@@ -243,7 +243,9 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
     char *psz_name;
 
     /* Allocate descriptor */
-    p_vout = vlc_object_create( p_parent, VLC_OBJECT_VOUT );
+    static const char typename[] = "video output";
+    p_vout = vlc_custom_create( p_parent, sizeof( *p_vout ), VLC_OBJECT_VOUT,
+                                typename );
     if( p_vout == NULL )
         return NULL;
 
@@ -304,8 +306,8 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
     p_vout->render_time  = 10;
     p_vout->c_fps_samples = 0;
     p_vout->b_filter_change = 0;
-    p_vout->pf_control = 0;
-    p_vout->p_parent_intf = 0;
+    p_vout->pf_control = NULL;
+    p_vout->p_window = NULL;
     p_vout->i_par_num = p_vout->i_par_den = 1;
 
     /* Initialize locks */
@@ -448,17 +450,17 @@ vout_thread_t * __vout_Create( vlc_object_t *p_parent, video_format_t *p_fmt )
         return NULL;
     }
 
+    vlc_object_set_destructor( p_vout, vout_Destructor );
+
     if( p_vout->b_error )
     {
         msg_Err( p_vout, "video output creation failed" );
 
-        /* Make sure the thread is destroyed */
+        /* Make sure the thread is destroyed and data released */
         vlc_object_release( p_vout );
         return NULL;
     }
 
-    vlc_object_set_destructor( p_vout, vout_Destructor );
-
     return p_vout;
 }
 
@@ -653,7 +655,7 @@ static int InitThread( vout_thread_t *p_vout )
         p_vout->b_direct = 0;
 
         /* Choose the best module */
-        p_vout->p_chroma = vlc_object_create( p_vout, VLC_OBJECT_FILTER );
+        p_vout->p_chroma = vlc_object_create( p_vout, sizeof(filter_t) );
         filter_t *p_chroma = p_vout->p_chroma;
         vlc_object_attach( p_chroma, p_vout );
         /* TODO: Set the fmt_in and fmt_out stuff here */
@@ -677,7 +679,8 @@ static int InitThread( vout_thread_t *p_vout )
             msg_Err( p_vout, "no chroma module for %4.4s to %4.4s",
                      (char*)&p_vout->render.i_chroma,
                      (char*)&p_vout->output.i_chroma );
-            vlc_object_detach( p_vout->p_chroma );
+
+            vlc_object_release( p_vout->p_chroma );
             p_vout->p_chroma = NULL;
             p_vout->pf_end( p_vout );
             vlc_mutex_unlock( &p_vout->change_lock );
@@ -1084,6 +1087,7 @@ static void RunThread( vout_thread_t *p_vout)
             /* A fatal error occurred, and the thread must terminate
              * immediately, without displaying anything - setting b_error to 1
              * causes the immediate end of the main while() loop. */
+            // FIXME pf_end
             p_vout->b_error = 1;
         }
 
@@ -1147,6 +1151,8 @@ static void RunThread( vout_thread_t *p_vout)
             if( !p_vout->b_direct )
             {
                 module_Unneed( p_vout->p_chroma, p_vout->p_chroma->p_module );
+                vlc_object_detach( p_vout->p_chroma );
+                vlc_object_release( p_vout->p_chroma );
                 p_vout->p_chroma = NULL;
             }
 
@@ -1221,7 +1227,8 @@ static void EndThread( vout_thread_t *p_vout )
     if( !p_vout->b_direct )
     {
         module_Unneed( p_vout->p_chroma, p_vout->p_chroma->p_module );
-        p_vout->p_chroma->p_module = NULL;
+        vlc_object_release( p_vout->p_chroma );
+        p_vout->p_chroma = NULL;
     }
 
     /* Destroy all remaining pictures */
@@ -1240,7 +1247,7 @@ static void EndThread( vout_thread_t *p_vout )
     /* Destroy the video filters2 */
     filter_chain_Delete( p_vout->p_vf2_chain );
 
-    /* Destroy translation tables */
+    /* Destroy translation tables FIXME if b_error is set, it can already be done */
     p_vout->pf_end( p_vout );
 
     /* Release the change lock */