Sender: root AT delorie DOT com Message-ID: <3E62BFC8.4E12DED8@ec-red.com> Date: Sun, 02 Mar 2003 21:36:56 -0500 From: Sergio Aguayo Organization: The GIMI-team X-Mailer: Mozilla 4.73 [en] (X11; U; Linux 2.4.20 i686) X-Accept-Language: en MIME-Version: 1.0 To: djgpp AT delorie DOT com Subject: Re: Problem with malloc/free References: <3E6225AD DOT 1341CC2B AT ec-red DOT com> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Reply-To: djgpp AT delorie DOT com 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 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