Changeset 684

Show
Ignore:
Timestamp:
12/24/09 15:22:43 (2 years ago)
Author:
erikd
Message:

Reduce memory leakage in plugins.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • sweep/trunk/plugins/ladspa/ladspameta.c

    r683 r684  
    6262 
    6363static GList * modules_list = NULL; 
     64static GList * proc_list = NULL; 
     65 
    6466static gboolean ladspa_meta_initialised = FALSE; 
    6567 
     
    654656 */ 
    655657static void 
    656 ladspa_meta_add_procs (gchar * dir, gchar * name, GList ** gl
     658ladspa_meta_add_procs (gchar * dir, gchar * name
    657659{ 
    658660#define PATH_LEN 256 
     
    722724      proc->custom_data = lm_custom_new (d, proc->param_specs); 
    723725 
    724       *gl = g_list_append (*gl, proc); 
     726      proc_list = g_list_append (proc_list, proc); 
    725727    } 
    726728  } 
     
    734736 */ 
    735737static void 
    736 ladspa_meta_init_dir (gchar * dirname, GList ** gl
     738ladspa_meta_init_dir (gchar * dirname
    737739{ 
    738740  DIR * dir; 
     
    750752    name = dirent->d_name; 
    751753    if (strcmp (name, ".") && strcmp (name, "..")) 
    752       ladspa_meta_add_procs (dirname, dirent->d_name, gl); 
     754      ladspa_meta_add_procs (dirname, dirent->d_name); 
    753755  } 
    754756 
     
    759761ladspa_meta_init (void) 
    760762{ 
    761   GList * gl = NULL; 
    762763  char * ladspa_path=NULL; 
    763764  char * next_sep=NULL; 
     
    778779    if (next_sep != NULL) *next_sep = '\0'; 
    779780     
    780     ladspa_meta_init_dir (ladspa_path, &gl); 
     781    ladspa_meta_init_dir (ladspa_path); 
    781782 
    782783    if (next_sep != NULL) ladspa_path = ++next_sep; 
     
    789790  if (saved_lp != NULL) free(saved_lp); 
    790791 
    791   return gl
     792  return proc_list
    792793} 
    793794 
     
    799800  if (!ladspa_meta_initialised) return; 
    800801 
     802  for (gl = proc_list; gl; gl = gl->next) { 
     803    sw_procedure * p = (sw_procedure *) gl->data; 
     804    if (p && p->custom_data) { 
     805      int j; 
     806 
     807      g_free (p->custom_data); 
     808      p->custom_data =  NULL; 
     809 
     810      for (j=0; j < p->nr_params; j++) { 
     811          if (p->param_specs[j].constraint_type == SW_PARAM_CONSTRAINED_RANGE) 
     812            g_free (p->param_specs[j].constraint.range); 
     813      } 
     814 
     815      g_free (p->param_specs); 
     816      p->param_specs = NULL; 
     817    } 
     818 
     819    g_free (p); 
     820    gl->data = NULL; 
     821  } 
     822 
     823  g_list_free (proc_list); 
     824  proc_list = NULL; 
     825 
    801826  for (gl = modules_list; gl; gl = gl->next) { 
    802827    dlclose(gl->data); 
    803   } 
     828    gl->data = NULL; 
     829  } 
     830  g_list_free (modules_list); 
     831  modules_list = NULL; 
     832 
    804833} 
    805834 
  • sweep/trunk/src/main.c

    r670 r684  
    259259  save_accels (); 
    260260 
     261  /* initialise plugins */ 
     262  release_plugins (); 
     263 
    261264  exit (0); 
    262265} 
  • sweep/trunk/src/plugin.c

    r683 r684  
    4242GList * plugins = NULL; 
    4343 
     44static GList * module_list = NULL; 
     45 
    4446static gint 
    4547cmp_proc_names (sw_procedure * a, sw_procedure * b) 
     
    4850} 
    4951 
    50 void 
     52static void 
    5153sweep_plugin_init (const gchar * path) 
    5254{ 
     
    6870  if (g_module_symbol (module, "plugin", &m_plugin_ptr)) { 
    6971        m_plugin = (sw_plugin *)m_plugin_ptr; 
     72        module_list = g_list_append (module_list, m_plugin); 
    7073    for (gl = m_plugin->plugin_init (); gl; gl = gl->next) { 
    7174      plugins = g_list_insert_sorted (plugins, (sw_procedure *)gl->data, 
     
    7376    } 
    7477  } 
    75 } 
    76  
    77 /* Initialise statically linked plugins */ 
    78 static void 
    79 init_static_plugins (void) 
    80 { 
    81 #if 0 
    82   plugins = g_list_append (plugins, &proc_normalise); 
    83   plugins = g_list_append (plugins, &proc_reverse); 
    84 #endif 
    8578} 
    8679 
     
    119112} 
    120113 
     114static void 
     115release_one (gpointer data, gpointer user_data) 
     116{ 
     117  sw_plugin *p = (sw_plugin *) data; 
     118  if (p && p->plugin_cleanup) 
     119    p->plugin_cleanup (); 
     120} 
     121 
     122 
    121123void 
    122124init_plugins (void) 
    123125{ 
    124   init_static_plugins (); 
    125  
    126126  if (g_module_supported ()) { 
    127127    init_dynamic_plugins (); 
    128128  } 
     129} 
    129130 
    130  
     131void 
     132release_plugins (void) 
     133
     134  g_list_foreach (module_list, release_one, NULL); 
     135  g_list_free (plugins); 
     136  plugins = NULL; 
    131137} 
  • sweep/trunk/src/plugin.h

    r7 r684  
    2626init_plugins (void); 
    2727 
     28void 
     29release_plugins (void); 
     30 
    2831#endif /* __PLUGIN_H__ */