bug-recutils
[Top][All Lists]
Advanced

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

Re: [bug-recutils] Python support


From: Michał Masłowski
Subject: Re: [bug-recutils] Python support
Date: Mon, 29 Jul 2013 17:59:08 +0200
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux)

Hi.

> However, I have been stuck with a double memory free problem
> for a few days. I think it is a bug in recutils. There seems to be a
> memory leak in rec_parse_db(). Please see the attached C program. I
> have used a function myfunc() to parse a rec file into a DB, print its
> size and then free everything. It runs this function myfunc() in an
> infinite loop. I used the top command to observe resident (RES) memory
> during run. It keeps increasing. Could you please check and let me
> know if this is a real problem, or I am probably missing something?

Valgrind is really useful for such issues.  It found leaks at two
places.

The struct rec_rset_fprops_s field fname is once allocated by strdup, it
needs to be deallocated with free.  I think it shouldn't be const,
otherwise it would get a warning.  If this is correct, the patch below
fixes it.  It's also available on the leaks-fname branch of
git://elderthing.mtjm.eu/mtjm-recutils.git.


From d6ae480397109a3c6e9b1199d7ab742aa3e5adcb Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Micha=C5=82=20Mas=C5=82owski?= <address@hidden>
Date: Mon, 29 Jul 2013 17:48:09 +0200
Subject: [PATCH] src: fix memory leak.

---
 ChangeLog      | 8 ++++++++
 src/rec-rset.c | 5 ++++-
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 3b78295..9908c34 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2013-07-29  Michał Masłowski  <address@hidden>
+
+       src: fix memory leak.
+       * src/rec-rset.c (struct rec_rset_fprops_s): Remove const from
+       fname, since it can be dynamically allocated.
+       (rec_rset_destroy): Free fname.
+       (rec_rset_update_field_props): Destroy the temporary fex.
+
 2013-06-23  Jose E. Marchesi  <address@hidden>
 
        src,doc,torture: fix the insertion of anonymous records in dbs.
diff --git a/src/rec-rset.c b/src/rec-rset.c
index 31eb846..ce4582c 100644
--- a/src/rec-rset.c
+++ b/src/rec-rset.c
@@ -51,7 +51,7 @@
 
 struct rec_rset_fprops_s
 {
-  const char *fname;
+  char *fname;
 
   bool key_p;          /* Primary key  */
   bool auto_p;         /* Auto-field.  */
@@ -252,6 +252,7 @@ rec_rset_destroy (rec_rset_t rset)
             {
               rec_type_destroy (aux->type);
             }
+          free (aux->fname);
           free (aux->type_name);
           props = props->next;
           free (aux);
@@ -1287,6 +1288,8 @@ rec_rset_update_field_props (rec_rset_t rset)
                   
                   free (field_type);
                 }
+
+              rec_fex_destroy (fex);
             }
 
           /* Update the key field.  */
-- 
1.8.3.4

Attachment: pgpqBUox6NSUo.pgp
Description: PGP signature


reply via email to

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