#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0

    Free() corrupted unsorted chunks


    We are migrating Pro*C code from SOLARIS to LINUX-Redhat.

    While migrating we face memory de-allocation issue intermittently when accessing large volume of data.

    Below is the part of the code:

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

    void free_frm_nde(node * nde_ptr)
    {
    static int num_ndes;
    int i;

    if (nde_ptr == NULL)
    return;

    if (nde_ptr->ptr_nxt != NULL)
    free_frm_nde(nde_ptr->ptr_nxt);

    for (i = 0; i < 7; i++)
    {
    if (nde_ptr->ptr_dwn[i] != NULL)
    free_frm_nde(nde_ptr->ptr_dwn[i]);
    }
    free(nde_ptr->ptr_dta); -- Error occurs here
    free(nde_ptr);
    }

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

    Below is the error message:

    *** glibc detected *** : ./filename: free(): corrupted unsorted chunks: 0x0a068b80 ***
    ======= Backtrace: =========
    /lib/libc.so.6[0xa044a5]
    /lib/libc.so.6(cfree+0x59)[0xa048e9]
    ./filename[0x8051180]
    ./filename[0x805115c]
    ./filename[0x805115c]
    ./filename[0x805115c]
    ./filename[0x805115c]
    ./filename[0x804cb31]
    ./filename[0x804eea7]
    ./filename[0x804ed8f]
    ./filename[0x8049a27]
    ./filename[0x804966f]
    /lib/libc.so.6(__libc_start_main+0xdc)[0x9b0e9c]
    ./[0x8048f21]
    ======= Memory map: ========
    0097c000-00997000 r-xp 00000000 fd:03 229417 /lib/ld-2.5.so
    00997000-00998000 r--p 0001a000 fd:03 229417 /lib/ld-2.5.so
    00998000-00999000 rw-p 0001b000 fd:03 229417 /lib/ld-2.5.so
    0099b000-00aef000 r-xp 00000000 fd:03 230066 /lib/libc-2.5.so
    00aef000-00af0000 ---p 00154000 fd:03 230066 /lib/libc-2.5.so
    00af0000-00af2000 r--p 00154000 fd:03 230066 /lib/libc-2.5.so
    00af2000-00af3000 rw-p 00156000 fd:03 230066 /lib/libc-2.5.so
    00af3000-00af6000 rw-p 00af3000 00:00 0
    00af8000-00b0d000 r-xp 00000000 fd:03 230096 /lib/libpthread-2.5.so
    00b0d000-00b0e000 ---p 00015000 fd:03 230096 /lib/libpthread-2.5.so

    Thanks in advance
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    > free(nde_ptr->ptr_dta); -- Error occurs here
    How do you know? The stack trace below contains no useful information.

    Speaking of which, if you compile the code with the -g flag, then the crash will give you lots of nice symbol names.

    Also, the crash only tells you where the problem was detected, it does not give you a cause for the crash (which is almost certainly some kind of array overrun).

    Since you're on Linux now, I suggest you investigate the valgrind tool.

    FWIW, you should avoid using recursion to delete the linked list. A very large list would result in deeply recursive calls, which may blow your program stack in extreme cases.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    2
    Rep Power
    0
    Thanks Salem.. we will check and keep you posted

IMN logo majestic logo threadwatch logo seochat tools logo