]> git.sesse.net Git - vlc/commitdiff
libvlc_InternalCreate: fix small race condition in error path
authorRémi Denis-Courmont <rem@videolan.org>
Sun, 4 May 2008 16:30:16 +0000 (19:30 +0300)
committerRémi Denis-Courmont <rem@videolan.org>
Sun, 4 May 2008 16:30:16 +0000 (19:30 +0300)
src/libvlc-common.c

index 46c8d44f7d68c6b46bf7e8e2b88627885f17bc58..4820619a4e61ee42a0f5949e5c81cb0c5e96723a 100644 (file)
@@ -158,9 +158,6 @@ libvlc_int_t * libvlc_InternalCreate( void )
     /* Now that the thread system is initialized, we don't have much, but
      * at least we have variables */
     vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
-
-    i_instances++;
-
     if( !p_libvlc_global->b_ready )
     {
         /* Guess what CPU we have */
@@ -170,15 +167,16 @@ libvlc_int_t * libvlc_InternalCreate( void )
 
         p_libvlc_global->b_ready = true;
     }
-    vlc_mutex_unlock( lock );
 
     /* Allocate a libvlc instance object */
     p_libvlc = vlc_object_create( p_libvlc_global, VLC_OBJECT_LIBVLC );
+    if( p_libvlc != NULL )
+        i_instances++;
+    vlc_mutex_unlock( lock );
+
     if( p_libvlc == NULL )
-    {
-        i_instances--;
         return NULL;
-    }
+
     p_libvlc->p_playlist = NULL;
     p_libvlc->p_interaction = NULL;
     p_libvlc->p_vlm = NULL;