Commit 3fa02df3 authored by Rémi Denis-Courmont's avatar Rémi Denis-Courmont

Destroy module cache data after loading completes

We do not need them afterward.
parent 964658d0
......@@ -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 *);
......
......@@ -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;
}
......
......@@ -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 *);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment