[vlc-devel] commit: Remove a whole bunch of non-sensical vlc_object_hold() ( Rémi Denis-Courmont )

git version control git at videolan.org
Mon Mar 16 19:52:24 CET 2009


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Mon Mar 16 20:37:34 2009 +0200| [c3cffb4f2fc50e3d8d6078a93b32f7163cb54a7c] | committer: Rémi Denis-Courmont 

Remove a whole bunch of non-sensical vlc_object_hold()

In one case (noted by Erwan Tulou), this also fixes a large leak.

There is _absolutely_ no point in holding an object and releasing it
immediately. Holding an object only makes sense if:
 - the object cannot vanish while calling vlc_object_hold(), and
 - either:
   - the object could have otherwise vanished before
     vlc_object_release(), or
   - there is no way to avoid the (otherwise not needed)
     vlc_object_hold() because it comes from another component.

Conversely, it makes no sense to hold an object, if:
 - it could vanish already while calling hold (race condition)
   -> this is *invalid* and might crash,
 - there is already a valid reference to the object throughout.

I don't know in which case that code was, but the popup menu definitely
does invalid object access in some cases. For instance:
 - start playing a single video,
 - seek to a few seconds before the end,
 - open the popup menu, go to video / deinterlace,
 - wait for the video to finish and the playlist to stop,
 - click on "X" from the deinterlace submenu.
Oops.

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

 modules/gui/qt4/menus.cpp |   21 ---------------------
 1 files changed, 0 insertions(+), 21 deletions(-)

diff --git a/modules/gui/qt4/menus.cpp b/modules/gui/qt4/menus.cpp
index 8f06648..946be41 100644
--- a/modules/gui/qt4/menus.cpp
+++ b/modules/gui/qt4/menus.cpp
@@ -503,8 +503,6 @@ QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
     }
 
     p_input = THEMIM->getInput();
-    if( p_input )
-        vlc_object_hold( p_input );
     p_aout = THEMIM->getAout();
     EnableStaticEntries( current, ( p_aout != NULL ) );
     AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
@@ -512,8 +510,6 @@ QMenu *QVLCMenu::AudioMenu( intf_thread_t *p_intf, QMenu * current )
     {
         vlc_object_release( p_aout );
     }
-    if( p_input )
-        vlc_object_release( p_input );
 
     return Populate( p_intf, current, varnames, objects );
 }
@@ -565,8 +561,6 @@ QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
     }
 
     p_input = THEMIM->getInput();
-    if( p_input )
-        vlc_object_hold( p_input );
 
     p_vout = THEMIM->getVout();
     VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
@@ -574,9 +568,6 @@ QMenu *QVLCMenu::VideoMenu( intf_thread_t *p_intf, QMenu *current )
     if( p_vout )
         vlc_object_release( p_vout );
 
-    if( p_input )
-        vlc_object_release( p_input );
-
     return Populate( p_intf, current, varnames, objects );
 }
 
@@ -621,8 +612,6 @@ QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
 
     /* Get the input and hold it */
     p_object = THEMIM->getInput();
-    if( p_object )
-        vlc_object_hold( p_object );
 
     InputAutoMenuBuilder( p_object, objects, varnames );
 
@@ -634,9 +623,6 @@ QMenu *QVLCMenu::RebuildNavigMenu( intf_thread_t *p_intf, QMenu *menu )
     PUSH_VAR( "prev-chapter" );
     PUSH_VAR( "next-chapter" );
 
-    if( p_object )
-        vlc_object_release( p_object );
-
     EnableStaticEntries( menu, (p_object != NULL ) );
     return Populate( p_intf, menu, varnames, objects );
 }
@@ -829,14 +815,12 @@ void QVLCMenu::VideoPopupMenu( intf_thread_t *p_intf )
     POPUP_BOILERPLATE;
     if( p_input )
     {
-        vlc_object_hold( p_input );
         vout_thread_t *p_vout = THEMIM->getVout();
         if( p_vout )
         {
             VideoAutoMenuBuilder( p_vout, p_input, objects, varnames );
             vlc_object_release( p_vout );
         }
-        vlc_object_release( p_input );
     }
     QMenu *menu = new QMenu();
     CREATE_POPUP;
@@ -848,12 +832,10 @@ void QVLCMenu::AudioPopupMenu( intf_thread_t *p_intf )
     POPUP_BOILERPLATE;
     if( p_input )
     {
-        vlc_object_hold( p_input );
         aout_instance_t *p_aout = THEMIM->getAout();
         AudioAutoMenuBuilder( p_aout, p_input, objects, varnames );
         if( p_aout )
             vlc_object_release( p_aout );
-        vlc_object_release( p_input );
     }
     QMenu *menu = new QMenu();
     CREATE_POPUP;
@@ -866,7 +848,6 @@ void QVLCMenu::MiscPopupMenu( intf_thread_t *p_intf )
 
     if( p_input )
     {
-        vlc_object_hold( p_input );
         varnames.push_back( "audio-es" );
         InputAutoMenuBuilder( p_input, objects, varnames );
         PUSH_SEPARATOR;
@@ -938,9 +919,7 @@ void QVLCMenu::PopupMenu( intf_thread_t *p_intf, bool show )
         }
 
         /* Input menu */
-        vlc_object_hold( p_input );
         InputAutoMenuBuilder( p_input, objects, varnames );
-        vlc_object_release( p_input );
 
         /* Audio menu */
         submenu = new QMenu( menu );




More information about the vlc-devel mailing list