confuse-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Confuse-devel] Fix for a memory leak in confuse


From: Franz Glasner
Subject: [Confuse-devel] Fix for a memory leak in confuse
Date: Sun, 2 Oct 2005 22:15:18 +0200

Hello,

there is a memory leak in current versions of libConfuse.
Memory allocated in the function cfg_dupopt_array() is not freed properly 
in
cfg_free_opt_array(). So default values for (string) lists are not freed.

Find the patch against the current cvs version to fix the leak below.

Best regards
Franz Glasner


*** confuse.c.ori       Sun Oct 02 21:04:16 2005
--- confuse.c   Sun Oct 02 21:16:13 2005
***************
*** 1189,1210 ****
 
  static void cfg_free_opt_array(cfg_opt_t *opts)
  {
      int i;
 
      for(i = 0; opts[i].name; ++i)
      {
          free(opts[i].name);
!         if(opts[i].type == CFGT_STR)
!             free(opts[i].def.string);
!         else if(opts[i].type == CFGT_SEC)
              cfg_free_opt_array(opts[i].subopts);
!         else if(opts[i].type == CFGT_FUNC || is_set(CFGF_LIST, 
opts[i].flags))
              free(opts[i].def.parsed);
      }
      free(opts);
  }
 
  DLLIMPORT void cfg_free(cfg_t *cfg)
  {
      int i;
 
--- 1189,1211 ----
 
  static void cfg_free_opt_array(cfg_opt_t *opts)
  {
      int i;
 
      for(i = 0; opts[i].name; ++i)
      {
          free(opts[i].name);
!         if(opts[i].type == CFGT_SEC && opts[i].subopts)
              cfg_free_opt_array(opts[i].subopts);
! 
!         if(is_set(CFGF_LIST, opts[i].flags) || opts[i].type == 
CFGT_FUNC)
              free(opts[i].def.parsed);
+         else if(opts[i].type == CFGT_STR)
+             free(opts[i].def.string);
      }
      free(opts);
  }
 
  DLLIMPORT void cfg_free(cfg_t *cfg)
  {
      int i;






reply via email to

[Prev in Thread] Current Thread [Next in Thread]