confuse-devel
[Top][All Lists]
Advanced

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

Re: [Confuse-devel] Possible memory leak in libconfuse


From: Thomas Stalder
Subject: Re: [Confuse-devel] Possible memory leak in libconfuse
Date: Tue, 30 Sep 2008 09:52:19 +0200
User-agent: Thunderbird 2.0.0.17 (Windows/20080914)

Yes,

test.c
########################
#include <confuse.h>

unsigned int test;

cfg_opt_t opts[] = {
        CFG_SIMPLE_INT("test", &test),
        CFG_END()
};
cfg_t * cfg;

int main(void)
{
        int err;

        cfg = cfg_init(opts, 0);
        err = cfg_parse(cfg, "test.conf");
        if (err==CFG_FILE_ERROR)
                printf("Error\n");
        if (err==CFG_PARSE_ERROR)
                printf("Parse Error");
        cfg_free(cfg);
        return 0;
}
##########################

> touch test.conf
> gcc test.c -lconfuse
> valgrind --leak-check=full --show-reachable=yes a.out

==1799== Memcheck, a memory error detector.
==1799== Copyright (C) 2002-2007, and GNU GPL'd, by Julian Seward et al.
==1799== Using LibVEX rev 1854, a library for dynamic binary translation.
==1799== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks LLP.
==1799== Using valgrind-3.3.1, a dynamic binary instrumentation framework.
==1799== Copyright (C) 2000-2007, and GNU GPL'd, by Julian Seward et al.
==1799== For more details, rerun with: -v
==1799==
==1799==
==1799== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 15 from 1)
==1799== malloc/free: in use at exit: 4 bytes in 1 blocks.
==1799== malloc/free: 10 allocs, 9 frees, 17,002 bytes allocated.
==1799== For counts of detected errors, rerun with: -v
==1799== searching for pointers to 1 not-freed blocks.
==1799== checked 58,812 bytes.
==1799==
==1799== 4 bytes in 1 blocks are still reachable in loss record 1 of 1
==1799==    at 0x4022649: malloc (vg_replace_malloc.c:207)
==1799==    by 0x403676B: cfg_yyalloc (lexer.c:2184)
==1799==    by 0x40367FE: cfg_yyensure_buffer_stack (lexer.c:1887)
==1799==    by 0x40368DC: cfg_yy_switch_to_buffer (lexer.c:1682)
==1799==    by 0x4036D5B: cfg_scan_fp_begin (lexer.l:354)
==1799==    by 0x4035481: cfg_parse_fp (confuse.c:1050)
==1799==    by 0x4035551: cfg_parse (confuse.c:1070)
==1799==    by 0x8048532: main (in /devel/a.out)
==1799==
==1799== LEAK SUMMARY:
==1799==    definitely lost: 0 bytes in 0 blocks.
==1799==      possibly lost: 0 bytes in 0 blocks.
==1799==    still reachable: 4 bytes in 1 blocks.
==1799==         suppressed: 0 bytes in 0 blocks.

Regards,

Thomas

Keith Mendoza a écrit :
Would it be possible for you to post your modified declaration of cfg_opt_t?

Thanks,
Keith

On Mon, Sep 29, 2008 at 11:16 AM, Thomas Stalder <address@hidden> wrote:

    Hello,

    I have add CFG_END at the end on my cfg_opt_t declaration, but I
    have the same memory leek.

    Regards,

    Thomas



    Keith Mendoza a écrit :

        Thomas,

        Actually you need to have CFG_END() at the end of your cfg_opt_t
        declaration. That's how the cfg_init knows that it's at the end
        of the opts[] array. See if that helps the memory leak that
        you're encountering.

        Keith

        On Fri, Sep 26, 2008 at 2:20 AM, Thomas Stalder
        <address@hidden> wrote:

           Hello,

           I have made a simple application who use libconfuse (2.6) test.c:
           ##########################################

           #include <confuse.h>

           unsigned int test;

           cfg_opt_t opts[] = {
                  CFG_SIMPLE_INT("test", &test)
           };
           cfg_t * cfg;

           int main(void)
           {
                  int err;

                  cfg = cfg_init(opts, 0);
                  err = cfg_parse(cfg, "test.conf");
                  if (err==CFG_FILE_ERROR)
                          printf("Error\n");
                  if (err==CFG_PARSE_ERROR)
                          printf("Parse Error");
                  cfg_free(cfg);
                  return 0;
           }

           ##########################################

           I compile test.c

           gcc test.c -lconfuse

           I installed valgrind (http://valgrind.org/)

           When I launch my test application with valgrind :

           valgrind --leak-check=full --show-reachable=yes a.out

           I have this result :

           ##########################################

           ==1512== Memcheck, a memory error detector.
           ==1512== Copyright (C) 2002-2007, and GNU GPL'd, by Julian
        Seward et al.
           ==1512== Using LibVEX rev 1854, a library for dynamic binary
           translation.
           ==1512== Copyright (C) 2004-2007, and GNU GPL'd, by OpenWorks
        LLP.
           ==1512== Using valgrind-3.3.1, a dynamic binary instrumentation
           framework.
           ==1512== Copyright (C) 2000-2007, and GNU GPL'd, by Julian
        Seward et al.
           ==1512== For more details, rerun with: -v
           ==1512==
           ==1512==
           ==1512== ERROR SUMMARY: 0 errors from 0 contexts (suppressed:
        15 from 1)
           ==1512== malloc/free: in use at exit: 4 bytes in 1 blocks.
           ==1512== malloc/free: 10 allocs, 9 frees, 17,002 bytes allocated.
           ==1512== For counts of detected errors, rerun with: -v
           ==1512== searching for pointers to 1 not-freed blocks.
           ==1512== checked 58,796 bytes.
           ==1512==
           ==1512== 4 bytes in 1 blocks are still reachable in loss
        record 1 of 1
           ==1512==    at 0x4022649: malloc (vg_replace_malloc.c:207)
           ==1512==    by 0x403676B: cfg_yyalloc (lexer.c:2184)
           ==1512==    by 0x40367FE: cfg_yyensure_buffer_stack
        (lexer.c:1887)
           ==1512==    by 0x40368DC: cfg_yy_switch_to_buffer (lexer.c:1682)
           ==1512==    by 0x4036D5B: cfg_scan_fp_begin (lexer.l:354)
           ==1512==    by 0x4035481: cfg_parse_fp (confuse.c:1050)
           ==1512==    by 0x4035551: cfg_parse (confuse.c:1070)
           ==1512==    by 0x8048532: main (in /root/a.out)
           ==1512==
           ==1512== LEAK SUMMARY:
           ==1512==    definitely lost: 0 bytes in 0 blocks.
           ==1512==      possibly lost: 0 bytes in 0 blocks.
           ==1512==    still reachable: 4 bytes in 1 blocks.
           ==1512==         suppressed: 0 bytes in 0 blocks.


           ##########################################


           libconfuse seems to not free a pointer allocated by cfg_yyalloc.


           Best regards,

           Thomas Stalder



           _______________________________________________
           Confuse-devel mailing list
           address@hidden <mailto:address@hidden>
        <mailto:address@hidden <mailto:address@hidden>>

           http://lists.nongnu.org/mailman/listinfo/confuse-devel



        ------------------------------------------------------------------------


        _______________________________________________
        Confuse-devel mailing list
        address@hidden <mailto:address@hidden>
        http://lists.nongnu.org/mailman/listinfo/confuse-devel






reply via email to

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