delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2001/04/22/13:00:12

Message-ID: <3AE30C3C.80F5CCCB@jps.net>
From: Dennis Yelle <dennis51 AT jps DOT net>
X-Mailer: Mozilla 4.75 [en] (Win98; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: nasty problems with free()
References: <3ae2dc55 DOT 2557776 AT news DOT dingoblue DOT net DOT au>
Lines: 46
Date: Sun, 22 Apr 2001 09:52:12 -0700
NNTP-Posting-Host: 216.119.26.43
X-Complaints-To: abuse AT onemain DOT com
X-Trace: nntp1.onemain.com 987958036 216.119.26.43 (Sun, 22 Apr 2001 12:47:16 EDT)
NNTP-Posting-Date: Sun, 22 Apr 2001 12:47:16 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Josh wrote:
> 
> ive been having some problems with freeing up some allocated memory.
> i use :
>         typedef struct {
>                     int x,y;
>         }Point;
> and
>         Point *p = calloc(n, sizeof(Point));
> to create an array of N point's
> then i play with the values a bit in the array (nothing unusual)
> but when i call   cfree(p);
> it will either drop back to windows (saying there was a some fault) or
> reboot my computer (this happens most of the time) :(
> after 20 odd reboots, 4 cups of coffee and alot of tinkering that got
> me nowhere, I thought i'd consult with the masters :)
> 
> ive placed my C code on my homepage for people to have a look at since
> it is too long to post here. It should compile straight away without
> any errors (youll need allegro) and only the calloc() and cfree() in
> main() needs to be examined. The rest of the functions work fine and
> do their jobs (so you shouldnt have to read/understand all the little
> functions.. just a few lines in main)
> 
> here it is :
> http://members.dingoblue.net.au/~10archway/djgpp/npolyswivel.c

The problem is right here:

> int main()
> {
>  int i,color,n;
>  // an array of N Points, used to create N-sided polygon
>  //Point *p = (Point *)malloc((n) * sizeof(Point));
>  Point *p = calloc(n, sizeof(Point));
>  Point centroid;
>  
>  allegro_init();

The variable 'n' is passed to calloc before you initialize it.

Dennis Yelle
-- 
I am a computer programmer and I am looking for a job.
There is a link to my resume here:  
http://table.jps.net/~vert/

- Raw text -


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