[Date Prev][Date Next] [Chronological] [Thread] [Top]

Tim Howes' 03.1.c: ldap_memfree/ber_free crashes



I would expect this to be a FAQ since it concerns the very first program in
Tim Howes' book, but searches in the 6 mailing list archives don't suggest
that there is any all-encompassing problem with the *free functions so I'm
probably doing something wrong at this end.  Could somebody help, please?

In a nutshell, the only way I can get Tim Howes' program 03.1.c to
compile and link against OpenLDAP 1.2.3 and then to run without
crashing is by defining out or removing all the calls to ldap_memfree()
and ber_free().

This could be related to some items in the bugs list concerning
ldap_memfree.  Since this function doesn't appear to be present in
OpenLDAP 1.2.3, I followed the advice I found there and #defined
ldap_memfree() to use free().  At runtime, the program then always
dumps core halfway through its output:

    (gdb) bt
    #0  0x4004f8f6 in chunk_free (ar_ptr=0x400a4420, p=0x80524b8) at malloc.c:2945
    #1  0x4004f7c1 in __libc_free (mem=0x80524c0) at malloc.c:2872
    #2  0x8048ed1 in main (argc=1, argv=0xbffff8f4) at 03.1.c:47

If ldap_memfree() is #defined out or removed completely, the program
again crashes but in a different place, namely in ber_free():

    (gdb) bt
    #0  0x4004fae1 in chunk_free (ar_ptr=0x400a4420, p=0x80528f0) at malloc.c:2969
    #1  0x4004f7c1 in __libc_free (mem=0x80528f8) at malloc.c:2872
    #2  0x804f82c in ber_free (ber=0x80528f8, freebuf=0) at io.c:267
    #3  0x8048eed in main (argc=1, argv=0xbffff8f4) at 03.1.c:50

If ber_free() is also #defined out or removed similarly, the program runs
fine, but obviously this isn't a real solution.

What's happening here?  Why is my memory allocation totally screwed?
These tests were run on RedHat 5.2/Intel using the stable source
distribution of OpenLDAP 1.2.3, and the program 03.1.c came from the
Macmillan support site at:

        http://www.mcp.com/info/1-57870/1-57870-000-0/

Cheers,

Rich Artym
rich@galacta.demon.co.uk