]> git.sesse.net Git - vlc/blobdiff - src/libvlc.c
Fix multiple deallocation (three deallocation for the same varaible that's a bit...
[vlc] / src / libvlc.c
index 00bcf0b611f901b96926deed795b1b6780db6170..45fa3a0e5e1a0d08030bce4439d4e5af6793f1d8 100644 (file)
@@ -151,10 +151,10 @@ void *vlc_hold (gc_object_t * p_gc)
 
 #if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
     refs = __sync_add_and_fetch (&p_gc->refs, 1);
-#elif defined (WIN32) && defined (__GNUC__)
-    refs = __builtin_choose_expr (sizeof (uintptr_t) == 4,
-               InterlockedIncrement (&p_gc->refs),
-               InterlockedIncrement64 (&p_gc->refs));
+#elif defined (WIN64)
+    refs = InterlockedIncrement64 (&p_gc->refs);
+#elif defined (WIN32)
+    refs = InterlockedIncrement (&p_gc->refs);
 #elif defined(__APPLE__)
     refs = OSAtomicIncrement32Barrier((int*)&p_gc->refs);
 #else
@@ -178,10 +178,10 @@ void vlc_release (gc_object_t *p_gc)
 
 #if defined (__GCC_HAVE_SYNC_COMPARE_AND_SWAP_4)
     refs = __sync_sub_and_fetch (&p_gc->refs, 1);
-#elif defined (WIN32) && defined (__GNUC__)
-    refs = __builtin_choose_expr (sizeof (uintptr_t) == 4,
-               InterlockedDecrement (&p_gc->refs),
-               InterlockedDecrement64 (&p_gc->refs));
+#elif defined (WIN64)
+    refs = InterlockedDecrement64 (&p_gc->refs);
+#elif defined (WIN32)
+    refs = InterlockedDecrement (&p_gc->refs);
 #elif defined(__APPLE__)
     refs = OSAtomicDecrement32Barrier((int*)&p_gc->refs);
 #else
@@ -228,6 +228,8 @@ static int  VerboseCallback( vlc_object_t *, char const *,
 
 static void InitDeviceValues( libvlc_int_t * );
 
+static vlc_mutex_t global_lock = VLC_STATIC_MUTEX;
+
 /**
  * Allocate a libvlc instance, initialize global data if needed
  * It also initializes the threading system
@@ -240,13 +242,12 @@ 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" );
+    vlc_mutex_lock( &global_lock );
     if( i_instances == 0 )
     {
         /* Guess what CPU we have */
         cpu_flags = CPUCapabilities();
         /* The module bank will be initialized later */
-        p_module_bank = NULL;
     }
 
     /* Allocate a libvlc instance object */
@@ -254,7 +255,7 @@ libvlc_int_t * libvlc_InternalCreate( void )
                                   VLC_OBJECT_GENERIC, "libvlc" );
     if( p_libvlc != NULL )
         i_instances++;
-    vlc_mutex_unlock( lock );
+    vlc_mutex_unlock( &global_lock );
 
     if( p_libvlc == NULL )
         return NULL;
@@ -364,10 +365,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     priv->psz_configfile = config_GetCustomConfigFile( p_libvlc );
 
     /* Check for plugins cache options */
-    if( config_GetInt( p_libvlc, "reset-plugins-cache" ) > 0 )
-    {
-        p_module_bank->b_cache_delete = true;
-    }
+    bool b_cache_delete = config_GetInt( p_libvlc, "reset-plugins-cache" ) > 0;
 
     /* Will be re-done properly later on */
     priv->i_verbose = config_GetInt( p_libvlc, "verbose" );
@@ -458,8 +456,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     psz_language = config_GetPsz( p_libvlc, "language" );
     if( psz_language && *psz_language && strcmp( psz_language, "auto" ) )
     {
-        bool b_cache_delete = p_module_bank->b_cache_delete;
-
         /* Reset the default domain */
         SetLanguage( psz_language );
 
@@ -471,7 +467,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
         if( !config_GetInt( p_libvlc, "ignore-config" ) )
             config_LoadConfigFile( p_libvlc, "main" );
         config_LoadCmdLine( p_libvlc, &i_argc, ppsz_argv, true );
-        p_module_bank->b_cache_delete = b_cache_delete;
     }
     free( psz_language );
 # endif
@@ -484,7 +479,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
      * default values.
      */
     module_LoadBuiltins( p_libvlc );
-    module_LoadPlugins( p_libvlc );
+    module_LoadPlugins( p_libvlc, b_cache_delete );
     if( p_libvlc->b_die )
     {
         b_exit = true;
@@ -493,7 +488,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     size_t module_count;
     module_t **list = module_list_get( &module_count );
     module_list_free( list );
-    msg_Dbg( p_libvlc, "module bank initialized (%u modules)", module_count );
+    msg_Dbg( p_libvlc, "module bank initialized (%zu modules)", module_count );
 
     /* Check for help on modules */
     if( (p_tmp = config_GetPsz( p_libvlc, "module" )) )
@@ -749,11 +744,6 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     if( priv->b_color )
         priv->b_color = config_GetInt( p_libvlc, "color" ) > 0;
 
-    /*
-     * Output messages that may still be in the queue
-     */
-    msg_Flush( p_libvlc );
-
     if( !config_GetInt( p_libvlc, "fpu" ) )
         cpu_flags &= ~CPU_CAPABILITY_FPU;
 
@@ -798,7 +788,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     /*
      * Choose the best memcpy module
      */
-    priv->p_memcpy_module = module_need( p_libvlc, "memcpy", "$memcpy", 0 );
+    priv->p_memcpy_module = module_need( p_libvlc, "memcpy", "$memcpy", false );
 
     priv->b_stats = config_GetInt( p_libvlc, "stats" ) > 0;
     priv->i_timers = 0;
@@ -893,10 +883,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
             *psz_parser = '\0';
             psz_parser++;
         }
-        psz_temp = (char *)malloc( strlen(psz_module) + sizeof(",none") );
-        if( psz_temp )
+        if( asprintf( &psz_temp, "%s,none", psz_module ) != -1)
         {
-            sprintf( psz_temp, "%s,none", psz_module );
             libvlc_InternalAddIntf( p_libvlc, psz_temp );
             free( psz_temp );
         }
@@ -934,7 +922,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
     }
 #endif
 
-    if( config_GetInt( p_libvlc, "file-logging" ) > 0 )
+    if( (config_GetInt( p_libvlc, "file-logging" ) > 0) &&
+        !config_GetInt( p_libvlc, "syslog" ) )
     {
         libvlc_InternalAddIntf( p_libvlc, "logger,none" );
     }
@@ -1136,7 +1125,7 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
                      p_libvlc->p_hotkeys );
     FREENULL( p_libvlc->p_hotkeys );
 
-    vlc_mutex_t *lock = var_AcquireMutex( "libvlc" );
+    vlc_mutex_lock( &global_lock );
     i_instances--;
 
     if( i_instances == 0 )
@@ -1144,9 +1133,8 @@ int libvlc_InternalDestroy( libvlc_int_t *p_libvlc )
         /* System specific cleaning code */
         system_End( p_libvlc );
     }
-    vlc_mutex_unlock( lock );
+    vlc_mutex_unlock( &global_lock );
 
-    msg_Flush( p_libvlc );
     msg_Destroy( p_libvlc );
 
     /* Destroy mutexes */