Thread: double free or corruption (fasttop)

  1. #1
    Registered User
    Join Date
    Jan 2011
    Posts
    3

    Unhappy double free or corruption (fasttop)

    Hello, I've a problem with this kind of error that appears into the function below :
    Code:
    void   conf_supprimer_config(
    Widget w,                    
    XtPointer   pst_client_data, 
    XtPointer   pst_call_data   
    )
    {
    /*Local variables   */
    
    int    *pi_position_list;        
    int     i_nbr_elements;          
    int    *pi_indice;               
    
    
    pi_indice = (int*)pst_client_data;
    pi_position_list = (int*)NULL;
    i_nbr_elements = 0;
    
    
    if ((*pi_indice != C_CONF_LISTE_STACNES) && (*pi_indice != C_CONF_LISTE_STAEXT))
       {
       msg_ano (MACH, C_CONF_ERR_LOGICIEL, (long)250, (long)NULL, (long)NULL, (long)NULL, (long)NULL);
       goto fin;
       }
     
    conf_i_indice = *pi_indice;
    
    XmListGetSelectedPos (conf_tw_config[conf_i_indice],
                          &pi_position_list,
                          &i_nbr_elements);
    
    
    if ( i_nbr_elements == 1 )
       {
       x_aff_valid(C_CONF_MESS_SUPPRESION_FIC, conf_supprimer_fichier, 
                                                            C_CONF_CONF_SUPP);
       }
    else
       {
       x_aff_msg ( C_CONF_ITEM_NONSELECTIONNE, C_X_ERREUR);
       }
    
    fin:
    /* Free memory                                           */
    if ( pi_position_list != (int*)NULL)
       {
       XtFree ((int*) pi_position_list);
       }
       
    }
    I supposed the error comes from XtFree but I don't understand the reason the error explains me and how to resolve the problem ...
    If someone knows ...

    Thx all !
    pepito

  2. #2
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Just to add the whole state of the error :

    *** glibc detected *** ../bin/conf: double free or corruption (fasttop): 0x08966b20 ***
    ======= Backtrace: =========
    /lib/libc.so.6[0x18b595]
    /lib/libc.so.6(cfree+0x59)[0x18b9d9]
    /usr/lib/libXt.so.6(XtFree+0x21)[0x3a3cd81]
    ../bin/conf[0x805dc3b]
    /usr/lib/libXt.so.6(XtCallCallbackList+0x11b)[0x3a3d3fb]
    /usr/lib/libXm.so.4[0x322b21]
    /usr/lib/libXt.so.6(XtCallCallbackList+0xaa)[0x3a3d38a]
    /usr/lib/libXm.so.4[0x32c5b0]
    /usr/lib/libXm.so.4[0x32df24]
    /usr/lib/libXm.so.4(_XmDispatchGadgetInput+0x17c)[0x2fd71c]
    /usr/lib/libXm.so.4(_XmGadgetActivate+0x3e)[0x3b4f1e]
    /usr/lib/libXt.so.6[0x3a73341]
    /usr/lib/libXt.so.6(_XtTranslateEvent+0x2ec)[0x3a73a1c]
    /usr/lib/libXt.so.6(XtDispatchEventToWidget+0x4f5)[0x3a4b615]
    /usr/lib/libXt.so.6[0x3a4bd9a]
    /usr/lib/libXt.so.6(XtDispatchEvent+0xc7)[0x3a4ac77]
    /usr/lib/libXt.so.6(XtAppMainLoop+0x4c)[0x3a4ae2c]
    ../bin/conf[0x8061004]
    /lib/libc.so.6(__libc_start_main+0xdc)[0x137e9c]
    ../bin/conf[0x804a2c1]
    ======= Memory map: ========
    00101000-00117000 r-xp 00000000 fd:00 205261 /usr/lib/libXmu.so.6.2.0
    00117000-00118000 rwxp 00016000 fd:00 205261 /usr/lib/libXmu.so.6.2.0
    00119000-0011f000 r-xp 00000000 fd:00 227853 /usr/lib/libxnsl.so.0.0.0
    0011f000-00120000 rwxp 00005000 fd:00 227853 /usr/lib/libxnsl.so.0.0.0
    00120000-00122000 rwxp 00120000 00:00 0
    00122000-00261000 r-xp 00000000 fd:00 2689196 /lib/libc-2.5.so
    ....

  3. #3
    The Dragon Reborn
    Join Date
    Nov 2009
    Location
    Dublin, Ireland
    Posts
    629
    eh..is this C code?
    You ended that sentence with a preposition...Bastard!

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Why isn't conf_supprimer_config() printed in the back trace?

    Is ../bin/conf your program? If so, compile it with -g (you should get function names resolved in the back trace).

    You can then use gdb to help you look around to try and find the problem.
    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.

  5. #5
    Registered User
    Join Date
    Jan 2011
    Posts
    3
    Yes, it is C code running with Linux RedHat 5.0
    The function is part of conf.c and that's why the /bin/conf refers to executable conf

    Anyway, I found the problem. This error is due to pi_position_list initialization (=(int*)NULL.
    I don't know why but it seems that this initialization is not needed and XtFree (X11 free memory function) try to free some already desallocated memory.

    So, by suppressing the initilialization line, it works.

    Another way to get rid of this kind of error is to write "export MALLOC_CHECK_=0" in command line, before running the program


    maybe these solutions might help others ...
    Thanx again

  6. #6
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by Eman View Post
    eh..is this C code?
    It appears to be, but the writer has a very unique formatting style.

  7. #7
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,909
    From GNU's website:

    If MALLOC_CHECK_ is set to 0, any detected heap corruption is silently ignored
    That scares the @#&$& out of me. You are doing something wrong and dangerous, so fix your problem instead of sweeping it under the rug. Not everybody who runs your program will have MALLOC_CHECK_=0 or want to set it every time they run it.

    Is XmListGetSelectedPos a function you wrote? That's where I would look for the actual cause of your problem, since that's the only thing that modifies pi_position_list in the code you posted. Does it do something different depending on whether the value in pi_position_list is NULL?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error in printf line,,,what's wrong?
    By mft_ika in forum C Programming
    Replies: 9
    Last Post: 03-19-2010, 08:46 PM
  2. double free or corruption (out)
    By Mouser58907 in forum C Programming
    Replies: 5
    Last Post: 02-25-2009, 12:20 AM
  3. Replies: 7
    Last Post: 11-26-2007, 01:11 PM
  4. Malloc - Free giving double free or corruption error
    By andrew.bolster in forum C Programming
    Replies: 2
    Last Post: 11-02-2007, 06:22 AM
  5. Help with multi function progam
    By WackoWolf in forum C Programming
    Replies: 22
    Last Post: 10-13-2005, 02:56 AM