[vlc-commits] Destroy module cache data after loading completes
Rémi Denis-Courmont
git at videolan.org
Sat Aug 13 21:24:47 CEST 2011
vlc | branch: master | Rémi Denis-Courmont <remi at remlab.net> | Sat Aug 13 20:26:05 2011 +0300| [3fa02df3184a17139e349fbe3db81a098e53908f] | committer: Rémi Denis-Courmont
Destroy module cache data after loading completes
We do not need them afterward.
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=3fa02df3184a17139e349fbe3db81a098e53908f
---
src/modules/cache.c | 26 +++++++++++++++-----------
src/modules/modules.c | 19 ++++---------------
src/modules/modules.h | 2 +-
3 files changed, 20 insertions(+), 27 deletions(-)
diff --git a/src/modules/cache.c b/src/modules/cache.c
index c43191f..77484cb 100644
--- a/src/modules/cache.c
+++ b/src/modules/cache.c
@@ -397,22 +397,19 @@ static int CacheLoadConfig( module_t *p_module, FILE *file )
static int CacheSaveBank( FILE *file, module_cache_t *const *, size_t );
-/*****************************************************************************
- * SavePluginsCache: saves the plugins cache to a file
- *****************************************************************************/
+/**
+ * Saves a module cache to disk, and release cache data from memory.
+ */
void CacheSave (vlc_object_t *p_this, const char *dir,
- module_cache_t *const *pp_cache, size_t n)
+ module_cache_t **entries, size_t n)
{
- char *filename, *tmpname;
+ char *filename = NULL, *tmpname = NULL;
if (asprintf (&filename, "%s"DIR_SEP CACHE_NAME, dir ) == -1)
- return;
+ goto out;
if (asprintf (&tmpname, "%s.%"PRIu32, filename, (uint32_t)getpid ()) == -1)
- {
- free (filename);
- return;
- }
+ goto out;
msg_Dbg (p_this, "saving plugins cache %s", filename);
FILE *file = vlc_fopen (tmpname, "wb");
@@ -423,7 +420,7 @@ void CacheSave (vlc_object_t *p_this, const char *dir,
goto out;
}
- if (CacheSaveBank (file, pp_cache, n))
+ if (CacheSaveBank (file, entries, n))
{
msg_Warn (p_this, "cannot write %s (%m)", tmpname);
clearerr (file);
@@ -443,6 +440,13 @@ void CacheSave (vlc_object_t *p_this, const char *dir,
out:
free (filename);
free (tmpname);
+
+ for (size_t i = 0; i < n; i++)
+ {
+ free (entries[i]->path);
+ free (entries[i]);
+ }
+ free (entries);
}
static int CacheSaveConfig (FILE *, const module_t *);
diff --git a/src/modules/modules.c b/src/modules/modules.c
index db525f8..bcff5a8 100644
--- a/src/modules/modules.c
+++ b/src/modules/modules.c
@@ -117,8 +117,6 @@ void module_InitBank( vlc_object_t *p_this )
{
p_bank = calloc (1, sizeof(*p_bank));
p_bank->i_usage = 1;
- p_bank->i_cache = 0;
- p_bank->pp_cache = NULL;
p_bank->head = NULL;
/* Everything worked, attach the object */
@@ -177,15 +175,6 @@ void module_EndBank( vlc_object_t *p_this, bool b_plugins )
p_module_bank = NULL;
vlc_mutex_unlock( &module_lock );
-#ifdef HAVE_DYNAMIC_PLUGINS
- while( p_bank->i_cache-- )
- {
- free( p_bank->pp_cache[p_bank->i_cache]->path );
- free( p_bank->pp_cache[p_bank->i_cache] );
- }
- free( p_bank->pp_cache );
-#endif
-
while( p_bank->head != NULL )
DeleteModule( p_bank, p_bank->head );
@@ -870,9 +859,8 @@ static void AllocateAllPlugins( vlc_object_t *p_this, module_bank_t *p_bank )
static void AllocatePluginPath( vlc_object_t *p_this, module_bank_t *p_bank,
const char *path, cache_mode_t mode )
{
- module_cache_t **cache;
+ module_cache_t **cache = NULL;
size_t count = 0;
- size_t offset = p_module_bank->i_cache;
switch( mode )
{
@@ -889,6 +877,8 @@ static void AllocatePluginPath( vlc_object_t *p_this, module_bank_t *p_bank,
msg_Dbg( p_this, "recursively browsing `%s'", path );
/* TODO: pass as argument, remove this hack */
+ p_bank->pp_cache = NULL;
+ p_bank->i_cache = 0;
p_bank->pp_loaded_cache = cache;
p_bank->i_loaded_cache = count;
/* Don't go deeper than 5 subdirectories */
@@ -907,8 +897,7 @@ static void AllocatePluginPath( vlc_object_t *p_this, module_bank_t *p_bank,
}
free( cache );
case CACHE_RESET:
- CacheSave( p_this, path, p_bank->pp_cache + offset,
- p_bank->i_cache - offset );
+ CacheSave (p_this, path, p_bank->pp_cache, p_bank->i_cache);
case CACHE_IGNORE:
break;
}
diff --git a/src/modules/modules.h b/src/modules/modules.h
index 797cd4e..2c8f9fb 100644
--- a/src/modules/modules.h
+++ b/src/modules/modules.h
@@ -130,7 +130,7 @@ void module_Unload (module_handle_t);
void CacheMerge (vlc_object_t *, module_t *, module_t *);
void CacheDelete(vlc_object_t *, const char *);
size_t CacheLoad (vlc_object_t *, const char *, module_cache_t ***);
-void CacheSave (vlc_object_t *, const char *, module_cache_t *const *, size_t);
+void CacheSave (vlc_object_t *, const char *, module_cache_t **, size_t);
module_t *CacheFind (module_cache_t *const *, size_t,
const char *, const struct stat *);
More information about the vlc-commits
mailing list