[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Seg fault calling free_menu
From: |
Clemens Ladisch |
Subject: |
Re: Seg fault calling free_menu |
Date: |
Tue, 01 Jun 2010 17:13:45 +0200 |
User-agent: |
Thunderbird 2.0.0.24 (Windows/20100228) |
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