Save one memory copy and fix the helper module leak
authorRémi Denis-Courmont <rem@videolan.org>
Mon, 17 Dec 2007 20:27:03 +0000 (20:27 +0000)
committerRémi Denis-Courmont <rem@videolan.org>
Mon, 17 Dec 2007 20:27:03 +0000 (20:27 +0000)
include/vlc_modules_macros.h
src/config/core.c
src/modules/entry.c

index d7011de..96a2aec 100644 (file)
@@ -121,14 +121,10 @@ E_(vlc_entry) ( module_t *p_module );
 
 #define vlc_module_end( )                                                     \
         }                                                                     \
-        res = config_Duplicate( p_module, p_config, ++i_config );             \
-        free( p_config );                                                     \
-        if (res)                                                              \
-            return res;                                                       \
-        return VLC_SUCCESS;                                                   \
+        return config_Duplicate( p_module, p_config, ++i_config );            \
                                                                               \
     error:                                                                    \
-        free( p_config );                                                     \
+        /* FIXME: config_Free( p_config ); */                                 \
         /* FIXME: cleanup submodules objects ??? */                           \
         return VLC_EGENERIC;                                                  \
     }                                                                         \
index 4031fb5..0caaa6f 100644 (file)
@@ -492,9 +492,6 @@ int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
     const module_config_t *p_item, *p_end = p_orig + n;
 
     /* Calculate the structure length */
-    p_module->i_config_items = 0;
-    p_module->i_bool_items = 0;
-
     for( p_item = p_orig; p_item < p_end; p_item++ )
     {
         if( p_item->i_type & CONFIG_ITEM )
@@ -508,19 +505,12 @@ int config_Duplicate( module_t *p_module, const module_config_t *p_orig,
         }
     }
 
-    /* Allocate memory */
-    p_module->p_config = (module_config_t *)calloc( n, sizeof(*p_orig) );
-    if( p_module->p_config == NULL )
-    {
-        msg_Err( p_module, "config error: can't duplicate p_config" );
-        return VLC_ENOMEM;
-    }
+    p_module->p_config = p_orig;
     p_module->confsize = n;
 
     /* Do the duplication job */
     for( size_t i = 0; i < n ; i++ )
     {
-        p_module->p_config[i] = p_orig[i];
         p_module->p_config[i].p_lock = &p_module->object_lock;
     }
     return VLC_SUCCESS;
index 4064862..94667fc 100644 (file)
@@ -40,6 +40,8 @@ module_t *vlc_module_create (vlc_object_t *obj)
     module->psz_object_name = module->psz_longname = default_name;
     module->psz_capability = "";
     module->i_score = 1;
+    module->i_config_items = module->i_bool_items = 0;
+
     return module;
 }
 
@@ -161,6 +163,13 @@ module_config_t *vlc_config_create (module_t *module, int type)
     tab[confsize].i_type = type;
     tab[confsize].p_lock = &module->object_lock;
 
+    if (type & CONFIG_ITEM)
+    {
+        module->i_config_items++;
+        if (type == CONFIG_ITEM_BOOL)
+            module->i_bool_items++;
+    }
+
     return tab + confsize;
 }