Date: Tue, 27 Oct 92 13:20:35 EST From: DJ Delorie To: turnbull AT ecolan DOT sbs DOT ohio-state DOT edu Cc: djgpp AT sun DOT soe DOT clarkson DOT edu Subject: FREEing NULL pointers > I thought you were always mod ANSI allowed to free a NULL pointer, but > not an uninitialized or previously free'd one. Nobody said that djgpp was ANSI. The sources for free() come from the BSD free'd sources - no modifications at all. > This is a serious bug, if true, with the standard library. Freeing a NULL > pointer is legal and covered in the definition of the function free. The SunOS 4.1 man pages state that free() takes a "a pointer to a block previously allocated by malloc(), calloc(), realloc(), malloc(), or memalign()." It also states that free() sets errno to EINVAL if the pointer passed does not fall into that category (that's a bug in djgpp). It does not explicitly state that it's legal to free NULL. Assuming that free can handle NULL is invalid, unless you are sure that it's *supposed* to be ANSI compliant. Trying to free NULL also implies that your program isn't checking the validity of pointers it is dealing with. DJ dj AT ctron DOT com Life is a banana.