[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Seg fault calling free_menu
From: |
pcazallas |
Subject: |
Re: Seg fault calling free_menu |
Date: |
Wed, 2 Jun 2010 00:19:13 -0700 (PDT) |
Clemens Ladisch wrote:
>
> pcazallas wrote:
>> registros = (ITEM **) malloc (sizeof (ITEM *));
>> while (sqlca.sqlcode != -501 && sqlca.sqlcode != 100)
>> {
>> posRegistros = registros[cReg];
>> registros = (ITEM **) realloc (registros, ((cReg+1) * sizeof(ITEM *))
>> );
>> registros[cReg] = posRegistros;
>
> This assignment is superfluous because registros[cReg] will be
> overwritten in the following line. This means that the posRegistros
> variable isn't needed at all.
>
>> registros[cReg] = (ITEM *) malloc (sizeof(ITEM));
>
> And this assignment is superfluous too because registros[cReg] will be
> overwritten in the following line.
>
> Menu items are allocated by new_item; you don't have to do this yourself.
>
>> registros[cReg] = new_item((char *)NULL, (char *)NULL);
>
> The last entry in registros[] must be a NULL pointer; this is not the
> same as a menu item with NULL strings.
>
> Just use "registros[cReg] = NULL".
>
>> /*free_menu(regMenu); <== Segmentation
>> fault */
>> free(regMenu);
>
> Don't call free; the memory was already freed by free_menu. If you do
> call free here, some random memory will be corrupted, which will create
> problems later.
>
>> for(int i = 0; i < cReg; i++){
>> free_item(registros[i]);
>> }
>
> free(registros);
>
>
> Regards,
> Clemens
>
> _______________________________________________
> Bug-ncurses mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-ncurses
>
>
Great Clemens =), it is working fine now after implementing your mods.
Thank you very much!
Pablo.
--
View this message in context:
http://old.nabble.com/Seg-fault-calling-free_menu-tp28740540p28750956.html
Sent from the Gnu - Ncurses mailing list archive at Nabble.com.