home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / sys / next / programm / 8245 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  2.0 KB

  1. Path: sparky!uunet!spool.mu.edu!enterpoop.mit.edu!eru.mt.luth.se!lunic!sunic!mcsun!sun4nl!nikhefh!t68
  2. From: t68@nikhefh.nikhef.nl (Jos Vermaseren)
  3. Newsgroups: comp.sys.next.programmer
  4. Subject: Re: Memory Allocation Error
  5. Message-ID: <2184@nikhefh.nikhef.nl>
  6. Date: 21 Jan 93 15:37:18 GMT
  7. References: <C16K2t.HGC@agora.rain.com>
  8. Organization: Nikhef-H, Amsterdam (the Netherlands).
  9. Lines: 30
  10.  
  11. In article <C16K2t.HGC@agora.rain.com>, bobb@agora.rain.com (Bob Beauchemin) writes:
  12. >   I'm having a problem with the NeXT 2.1 compiler and wonder if anyone else
  13. > has experienced it. Code that compiles OK and works on other platforms
  14. > fails on the NeXT. The error messages (at program execution) are:
  15. >
  16. The argument that it runs on other platforms is not so good. Many old style
  17. UNIX programmers messed up int's and pointers freely.....
  18.  
  19. I have had similar problems with free when you give it a pointer that
  20. you did not get from malloc before (like a NULL pointer). It can result
  21. in very erratic behaviour after the (illegal) freeing.
  22. It is just one of those things....
  23.   The standard says what free should do when everything is swell but
  24. of course the question is what it should do when things are wrong. Standards
  25. rarely specify. You could crash the program, continue execution which a
  26. poisoned system (what NeXT does) or when you manage to set up malloc and
  27. free in such a way that nothing gets poisoned just keep running
  28. (like many other systems do).
  29. Unless there is a real programming error inside Mach, I guess formally you
  30. cannot blame NeXT too much. You should have a good look inside your program
  31. and make sure that each pointer that is freed is allowed to be freed.
  32. A little macro like
  33. #define MyFree(x)  if ( x != NULL ) { free(x); x = NULL; }
  34. can work miracles. You could sneak in an else with an error message if you
  35. want to see whether you try to free the same thing twice.
  36. Of course it would be nice if the NeXT would crash the program rather than
  37. continue running.....  Or would it? Maybe a good error message?
  38.  
  39. Jos Vermaseren
  40.