[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: |
Tue, 1 Jun 2010 06:53:52 -0700 (PDT) |
Clemens Ladisch wrote:
>
> pcazallas wrote:
>> When I try to free a "MENU* myMenu" var calling "free_menu(myMenu)", it
>> throws a Segfault. If I free the variable just calling "free(myMenu)", it
>> does not occur...
>>
>> I am allocating memory for the menu
>
> With new_menu?
>
>> and the items relying it, and freeing all of them as well.
>
> Are you freeing the items after the menu?
>
>> Any suggestion about which could be the reason of the Segfault?
>
> Some bug? In your source code? Which I don't know ...
>
>
> Regards,
> Clemens
>
> _______________________________________________
> Bug-ncurses mailing list
> address@hidden
> http://lists.gnu.org/mailman/listinfo/bug-ncurses
>
>
Allright, sorry... I was not clear enough...
this is the code:
----------------------------------------------------------------------
MENU *regMenu;
ITEM **registros;
ITEM *posRegistros;
/*
I have to load the menu dynamically, because the data to fill the items is
gotten from a fetch to a database cursor
*/
cReg=0;
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;
registros[cReg] = (ITEM *) malloc (sizeof(ITEM));
registros[cReg] = new_item(lista[cReg]->full_info, NULL);
cReg++;
}
registros[cReg] = new_item((char *)NULL, (char *)NULL);
regMenu = new_menu(registros);
set_menu_win(regMenu, monitorData);
set_menu_sub(regMenu, derwin(monitorData, ROWS_MONITOR_DATA, 78, 0, 1));
set_menu_format(regMenu, ROWS_MONITOR_DATA, 1);
set_menu_mark(regMenu, "");
post_menu(regMenu);
wrefresh(myWin);
.............
.............
unpost_menu(regMenu);
/*free_menu(regMenu); <== Segmentation fault */
free(regMenu);
for(int i = 0; i < cReg; i++){
free_item(registros[i]);
}
----------------------------------------------------------------------
So, the first time that the program reaches the part of freeing the menu, it
works, but It does not the second one...
Regards,
Pablo.
--
View this message in context:
http://old.nabble.com/Seg-fault-calling-free_menu-tp28740540p28742054.html
Sent from the Gnu - Ncurses mailing list archive at Nabble.com.