delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2003/03/02/11:15:02

From: "A. Sinan Unur" <asu1 AT c-o-r-n-e-l-l DOT edu>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Problem with malloc/free
Date: 2 Mar 2003 16:04:00 GMT
Organization: Cornell University
Lines: 32
Sender: asu1 AT cornell DOT invalid (on pool-141-149-206-96.syr.east.verizon.net)
Message-ID: <Xns933270944F6EBasu1cornelledu@132.236.56.8>
References: <3E6225AD DOT 1341CC2B AT ec-red DOT com>
NNTP-Posting-Host: pool-141-149-206-96.syr.east.verizon.net
X-Trace: news01.cit.cornell.edu 1046621040 27028 141.149.206.96 (2 Mar 2003 16:04:00 GMT)
X-Complaints-To: usenet AT news01 DOT cit DOT cornell DOT edu
NNTP-Posting-Date: 2 Mar 2003 16:04:00 GMT
User-Agent: Xnews/5.04.25
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019