]> git.sesse.net Git - vlc/blobdiff - src/misc/messages.c
revision: No need for the -n in echo. Choke Darwin.
[vlc] / src / misc / messages.c
index 29031f042d6fe22344c54fa29a3f4270546f9468..a453bccd545d696eaef9d875e295779c31059268 100644 (file)
@@ -61,6 +61,13 @@ typedef struct
     char * psz_message;
 } msg_context_t;
 
+static void cleanup_msg_context (void *data)
+{
+    msg_context_t *ctx = data;
+    free (ctx->psz_message);
+    free (ctx);
+}
+
 static vlc_threadvar_t msg_context;
 static uintptr_t banks = 0;
 
@@ -117,7 +124,7 @@ void msg_Create (libvlc_int_t *p_libvlc)
 
     vlc_mutex_lock( &msg_stack_lock );
     if( banks++ == 0 )
-        vlc_threadvar_create( &msg_context, NULL );
+        vlc_threadvar_create( &msg_context, cleanup_msg_context );
     vlc_mutex_unlock( &msg_stack_lock );
 }
 
@@ -153,7 +160,7 @@ void __msg_DisableObjectPrinting (vlc_object_t *p_this, char * psz_object)
  * Destroy the message queues
  *
  * This functions prints all messages remaining in the queues,
- * then frees all the allocated ressources
+ * then frees all the allocated resources
  * No other messages interface functions should be called after this one.
  */
 void msg_Destroy (libvlc_int_t *p_libvlc)
@@ -468,9 +475,6 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
         p_obj = p_obj->p_parent;
     }
 
-    msg_bank_t *p_queue = &QUEUE;
-    vlc_mutex_lock( &p_queue->lock );
-
     /* Fill message information fields */
     p_item->i_type =        i_type;
     p_item->i_object_id =   (uintptr_t)p_this;
@@ -480,6 +484,9 @@ static void QueueMsg( vlc_object_t *p_this, int i_type, const char *psz_module,
     p_item->psz_header =    psz_header;
 
     PrintMsg( p_this, p_item );
+
+    msg_bank_t *p_queue = &QUEUE;
+    vlc_mutex_lock( &p_queue->lock );
 #define bank p_queue
     for (int i = 0; i < bank->i_sub; i++)
     {
@@ -556,7 +563,6 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
             return;
     }
 
-    int canc = vlc_savecancel ();
 #ifdef UNDER_CE
 #   define CE_WRITE(str) WriteFile( QUEUE.logfile, \
                                     str, strlen(str), &i_dummy, NULL );
@@ -570,6 +576,7 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
     FlushFileBuffers( QUEUE.logfile );
 
 #else
+    int canc = vlc_savecancel ();
     /* Send the message to stderr */
     utf8_fprintf( stderr, "[%s%p%s] %s%s%s %s%s: %s%s%s\n",
                   priv->b_color ? GREEN : "",
@@ -592,12 +599,14 @@ static void PrintMsg ( vlc_object_t * p_this, msg_item_t * p_item )
 
 static msg_context_t* GetContext(void)
 {
-    msg_context_t *p_ctx = vlc_threadvar_get( &msg_context );
+    msg_context_t *p_ctx = vlc_threadvar_get( msg_context );
     if( p_ctx == NULL )
     {
-        MALLOC_NULL( p_ctx, msg_context_t );
+        p_ctx = malloc( sizeof( msg_context_t ) );
+        if( !p_ctx )
+            return NULL;
         p_ctx->psz_message = NULL;
-        vlc_threadvar_set( &msg_context, p_ctx );
+        vlc_threadvar_set( msg_context, p_ctx );
     }
     return p_ctx;
 }