bug-recutils
[Top][All Lists]
Advanced

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

Re: [bug-recutils] Python support


From: Maninya M
Subject: Re: [bug-recutils] Python support
Date: Wed, 31 Jul 2013 20:24:23 +0530

Hi,

> 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.

Thanks, I applied the patch, but I am still getting the memory leak
when I run the sample.c program (which I sent). I had tried using
valgrind, but could you tell me how exactly you are adding debug
symbols during compilation? I tried these:
- Add -g option to CFLAGS during setup build
- Installing python-dbg and running valgrind with a suppressions file
(required for python with valgrind).
for the python code.
For the C code, I saw that the C flags are set with -g in the
makefile. I even installed the software files at a particular location
to make sure it wasn't using another version. I am still unable to get
line numbers in recutils files during debug. So I could not exactly
find which line is causing the leak. Only the function name,
rec_parse_db() is shown.

Please check the updated python branch, for more read only processing functions.
I have written bindings for some modify functions, such as
insert_rset() in DB (I have not uploaded it). It is inserting fine,
but I get the same double free memory error.
I have also written a binding for rec_db_query() function, but it does
not work. It throws an "undefined symbol" error when I call the C
recdb query function. Why is that so?

My loadfile() function loads a file into a DB by erasing the previous
data in it. This is because the C parser function does not append the
parsed data in the DB, but overwrites it. Is this how it should be? At
present we can add more data from a file to a DB by parsing the file
into another DB, getting an rset, and then inserting the rset into the
DB (this works for me, except for the memory error at the  end).



On 29 July 2013 21:29, Michał Masłowski <address@hidden> wrote:
>
> 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
>



-- 
Maninya



reply via email to

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