gnokii-users
[Top][All Lists]
Advanced

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

memleaks after calling gn_cfg_file_read


From: Sander Wichers
Subject: memleaks after calling gn_cfg_file_read
Date: Fri, 11 Mar 2005 18:33:10 +0100

Hi,

Hope it's the right place to post this.

There appears to be memory leaking after calling gn_cfg_file_read, which
indirectly fills the gn_cfg_info linked lists. I haven't checked the cvs
version but I've grepped for gn_cfg_info in 0.6.4 and I don't see any memory
being freed on this variable. 

Anyway, I have some cleanup code for you to add. (These were diffed  against
0.6.4)

Yours,

Sander Wichers 
 

*** gnokii/common/cfgreader.c   Sun Oct 17 22:44:20 2004
--- common/cfgreader.c  Fri Mar 11 13:50:52 2005
***************
*** 457,462 ****
--- 457,505 ----
        return retval;
  }
  
+ void gn_cfg_close_entry(struct gn_cfg_entry *ent)
+ {
+     if (ent->next != NULL) {
+         gn_cfg_close_entry(ent->next);
+         free(ent->next);
+     }
+ 
+     if (ent->value)
+         free(ent->value);
+     if (ent->key)
+         free(ent->key);
+ }
+ 
+ void gn_cfg_close_header(struct gn_cfg_header *head)
+ {
+     if (head->entries != NULL) {
+         gn_cfg_close_entry(head->entries);
+         free(head->entries);
+         head->entries = NULL;
+     }
+ 
+     if (head->next != NULL) {
+         gn_cfg_close_header(head->next);
+         free(head->next);
+         head->next = NULL;
+     }
+     if (head->section)
+         free(head->section);
+     head->prev = NULL;
+ }
+ 
+ API int gn_cfg_close()
+ {
+     if (gn_cfg_info != NULL)
+     {
+         gn_cfg_close_header(gn_cfg_info);
+         free(gn_cfg_info);
+         gn_cfg_info = NULL;
+     }
+ 
+     return 0;
+ }
+ 
  API int gn_cfg_file_read(const char *file)
  {
        char *val;

*** gnokii/include/gnokii.h     Sun Oct 17 22:44:22 2004
--- include/gnokii.h    Fri Mar 11 13:34:24 2005
***************
*** 104,109 ****
--- 104,110 ----
  API int gn_cfg_file_read(const char *filename);
  API int gn_cfg_read_default();
  API int gn_cfg_phone_load(const char *iname, struct gn_statemachine *state);
+ API int gn_cfg_close();
  
  /* In/Out routines, file formats */
  API int gn_phonebook2vcard(FILE *f, gn_phonebook_entry *entry, char 
*location);

reply via email to

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