delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2002/12/14/05:00:36

From: "Lars O. Hansen" <lars DOT o DOT hansen AT gmx DOT de>
Newsgroups: comp.os.msdos.djgpp
Subject: problem with malloc and free
Date: Sat, 14 Dec 2002 10:47:30 +0100
Organization: 1&1 Internet AG
Lines: 46
Message-ID: <ateunh$mv3$1@news.online.de>
NNTP-Posting-Host: p5083867a.dip0.t-ipconnect.de
X-Trace: news.online.de 1039859249 23523 80.131.134.122 (14 Dec 2002 09:47:29 GMT)
X-Complaints-To: abuse AT online DOT de
NNTP-Posting-Date: 14 Dec 2002 09:47:29 GMT
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1106
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

the following code, if compiled per "gcc test.c" and executed (DOS), crashes for some compilations
and then when compiled again crashes not and then again when compiled again, crashes again.

if the (float*) casts are removed, the code always crashes.

if then either atexit(freeall), or either free(cxphi) in main or either free(cm) in freeall or
either free(cxphi) in freeall is removed, the code does not crash.

I am using djgpp downloaded last Wednesday from Zip Picker.



int array_size=360;

float *cm;
float *cxphi;


void setupall(void);
void freeall(void);


int main()
 {
  cm=(float*)malloc(3*sizeof(float)*array_size);
  cxphi=(float*)malloc(4*sizeof(float)*array_size);

  atexit(freeall);

  free(cxphi);
 }

void freeall()
 {
  free(cm);
  free(cxphi);
 }



Any help?


Lars


- Raw text -


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