[vlc-commits] Allocate message item on the stack

Rémi Denis-Courmont git at videolan.org
Wed May 11 18:54:34 CEST 2011


vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Wed May 11 18:01:15 2011 +0300| [0c86c2c957b2c658e7b36ee558d111a8ce7f36a6] | committer: Rémi Denis-Courmont

Allocate message item on the stack

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

 src/misc/messages.c |   38 ++++++++++++++++++--------------------
 1 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/src/misc/messages.c b/src/misc/messages.c
index f7f25b3..64d7697 100644
--- a/src/misc/messages.c
+++ b/src/misc/messages.c
@@ -261,10 +261,8 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
                            const char *psz_module,
                            const char *psz_format, va_list _args)
 {
-    size_t      i_header_size;             /* Size of the additionnal header */
     vlc_object_t *p_obj;
     char *       psz_str = NULL;                 /* formatted message string */
-    char *       psz_header = NULL;
     va_list      args;
 
     assert (p_this);
@@ -366,14 +364,18 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
     }
     uselocale (locale);
 
-    msg_item_t * p_item = malloc (sizeof (*p_item));
-    if (p_item == NULL)
-        return; /* Uho! */
+    /* Fill message information fields */
+    msg_item_t msg;
 
-    p_item->psz_module = p_item->psz_msg = p_item->psz_header = NULL;
+    msg.i_type = i_type;
+    msg.i_object_id = (uintptr_t)p_this;
+    msg.psz_object_type = p_this->psz_object_type;
+    msg.psz_module = strdup( psz_module );
+    msg.psz_msg = psz_str;
 
+    char *psz_header = NULL;
+    size_t i_header_size = 0;
 
-    i_header_size = 0;
     p_obj = p_this;
     while( p_obj != NULL )
     {
@@ -399,15 +401,9 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
         p_obj = p_obj->p_parent;
     }
 
-    /* Fill message information fields */
-    p_item->i_type =        i_type;
-    p_item->i_object_id =   (uintptr_t)p_this;
-    p_item->psz_object_type = p_this->psz_object_type;
-    p_item->psz_module =    strdup( psz_module );
-    p_item->psz_msg =       psz_str;
-    p_item->psz_header =    psz_header;
+    msg.psz_header = psz_header;
 
-    PrintMsg( p_this, p_item );
+    PrintMsg( p_this, &msg );
 
     vlc_rwlock_rdlock (&bank->lock);
     for (int i = 0; i < bank->i_sub; i++)
@@ -416,17 +412,17 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
         libvlc_priv_t *priv = libvlc_priv( sub->instance );
         msg_bank_t *bank = priv->msg_bank;
         void *val = vlc_dictionary_value_for_key( &bank->enabled_objects,
-                                                  p_item->psz_module );
+                                                  msg.psz_module );
         if( val == kObjectPrintingDisabled ) continue;
         if( val != kObjectPrintingEnabled  ) /*if not allowed */
         {
             val = vlc_dictionary_value_for_key( &bank->enabled_objects,
-                                                 p_item->psz_object_type );
+                                                msg.psz_object_type );
             if( val == kObjectPrintingDisabled ) continue;
             if( val == kObjectPrintingEnabled  ); /* Allowed */
             else if( !bank->all_objects_enabled ) continue;
         }
-        switch( p_item->i_type )
+        switch( msg.i_type )
         {
             case VLC_MSG_INFO:
             case VLC_MSG_ERR:
@@ -440,10 +436,12 @@ void msg_GenericVa (vlc_object_t *p_this, int i_type,
                 break;
         }
 
-        sub->func (sub->opaque, p_item, 0);
+        sub->func (sub->opaque, &msg, 0);
     }
     vlc_rwlock_unlock (&bank->lock);
-    msg_Free (p_item);
+    free (msg.psz_module);
+    free (msg.psz_msg);
+    free (msg.psz_header);
 }
 
 /*****************************************************************************



More information about the vlc-commits mailing list