Mail Archives: djgpp/2003/03/02/21:40:36
No, i'm declaring an array of pointers:
char *pcode[20];
then i allocate memory for each one in a "for" as follows:
pcode[i] = (char*)malloc(length of file to load);
when i finish, i call:
free(pcode[i]);
there's where the SIGSEGV occurs.
Sergio
"A. Sinan Unur" wrote:
> Sergio Aguayo <sergioag AT ec-red DOT com> wrote in news:3E6225AD DOT 1341CC2B AT ec-
> red.com:
>
> > The problem is the following: i'm using DJGPP (the version available
> > right now), i'm using malloc with an array of pointers (20 char *) for
> > loading a file (a total of 20 files at once). The problem comes when i
> > call free to release that memory, there occures a SIGSEGV signal. I'm
> > also using allegro.
>
> without some code that we can compile and diagnose, there is not much we
> can do.
>
> however, you may have only allocated memory for the pointers, and nothing
> for those pointers to point to.
>
> int i;
>
> char **ptr_array = malloc(20 * sizeof(char *));
> /* check if malloc returned NULL and handle the error */
> for(i = 0; i != 20; ++i)
> {
> ptr_array[i] = malloc(some space);
> /* check if malloc returned NULL and handle the error */
> }
>
> the codeabove was typed directly into the newsreader, and not tested.
>
> --
> A. Sinan Unur
> asu1 AT c-o-r-n-e-l-l DOT edu
> Remove dashes for address
> Spam bait: mailto:uce AT ftc DOT gov
- Raw text -