[vlc-devel] commit: Remove useless i_refcount == 0 case and fix a tiny race condition. ( Rémi Denis-Courmont )

git version control git at videolan.org
Wed May 7 21:39:45 CEST 2008


vlc | branch: master | Rémi Denis-Courmont <rem at videolan.org> | Wed May  7 22:40:48 2008 +0300| [19bd84c786fecb77531073b697aad4d3c221d15d]

Remove useless i_refcount == 0 case and fix a tiny race condition.

When i_refcount drops to zero (under the structure lock), the object is
removed from the objects table before the structure lock is released.
Hence, no objects with a nul refcount can ever be left in the table.

There is an unlikely race condition if another object is removed from
the table right between we unlock the structure lock but before we
return from vlc_object_get() (so that the i_middle offset gets wrong).

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

 src/misc/objects.c |   18 +++++-------------
 1 files changed, 5 insertions(+), 13 deletions(-)

diff --git a/src/misc/objects.c b/src/misc/objects.c
index 97db4e1..64862e0 100644
--- a/src/misc/objects.c
+++ b/src/misc/objects.c
@@ -686,6 +686,7 @@ void * vlc_object_get( int i_id )
     int i_max, i_middle;
     vlc_object_t **pp_objects;
     libvlc_global_data_t *p_libvlc_global = vlc_global();
+    vlc_object_t *obj = NULL;
 
     vlc_mutex_lock( &structure_lock );
 
@@ -710,33 +711,24 @@ void * vlc_object_get( int i_id )
             else
             {
                 /* This happens when there are only two remaining objects */
-                if( pp_objects[i_middle+1]->i_object_id == i_id
-                    && vlc_internals( pp_objects[i_middle+1] )->i_refcount > 0 )
+                if( pp_objects[i_middle+1]->i_object_id == i_id )
                 {
                     vlc_object_yield_locked( pp_objects[i_middle+1] );
-                    vlc_mutex_unlock( &structure_lock );
-                    return pp_objects[i_middle+1];
+                    obj = pp_objects[i_middle+1];
                 }
                 break;
             }
         }
-        else if( vlc_internals( pp_objects[i_middle] )->i_refcount > 0 )
+        else
         {
             vlc_object_yield_locked( pp_objects[i_middle] );
             vlc_mutex_unlock( &structure_lock );
             return pp_objects[i_middle];
         }
-
-        if( i_max == 0 )
-        {
-            /* this means that i_max == i_middle, and since we have already
-             * tested pp_objects[i_middle]), p_found is properly set. */
-            break;
-        }
     }
 
     vlc_mutex_unlock( &structure_lock );
-    return NULL;
+    return obj;
 }
 
 /**




More information about the vlc-devel mailing list