From: Joseph Donahue Newsgroups: comp.os.msdos.djgpp Subject: Re: free() question Date: Fri, 10 Jan 1997 12:49:19 -0500 Lines: 27 Message-ID: <32D6811F.9B1@ibm.net> References: <199701081113 DOT MAA01144 AT gilberto DOT physik DOT rwth-aachen DOT de> <32D4155A DOT 51F4 AT exis DOT net> Reply-To: jwdonah AT ibm DOT net NNTP-Posting-Host: slip129-37-241-242.wa.us.ibm.net Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Joe Wright wrote: > <<< Snip >>>> > Good habits are as hard to break as bad ones. I always check the > return from malloc (or fopen) in a conditional like: > > if ((ptr1 = (char *)malloc(1024)) == NULL) > do_not_pass_go(); > ptr2 = ptr1; > > There is little you can do if malloc() fails and there is no use > continuing with the program. Make it stop and try to fix it. > In any case, if malloc() fails, neither ptr1 nor ptr2 contain valid > pointers. And there is nothing to free() anyway. I must agree with you (Joe) about good habits. But did you intend to give the impression the program should terminate? If malloc() fails on a modern multitasking operating system, there is still the chance that giving the user the oportunity to close some files or stop some other non-essential programs will free enough memory for the program to continue without reloading/reinitializing. Ah...while I'm here...could someone please tell me what djgpp is? I assume this is some C/C++ compiler?