Re: Access violation in free()
- From: Tor Rustad <tor_rustad@xxxxxxxxxxx>
- Date: Sun, 02 Sep 2007 22:55:03 +0200
Richard Heathfield wrote:
Tor Rustad said:
Unless you are writing e.g. a non-stop server (or a library for it,
kernel mode code etc.), the normally best thing to do on memory
failures, is simply to exit.
We've had this debate over and over, and I think it's fair to say that the balance of expert opinion is against you (although it's far from unanimous), although of course it does depend very much on what you're writing (as you suggest). The consensus seems to be that, if you're writing 'generic' code - code that you expect to be used many times by many programs - then you should report errors rather than terminate the program.
In generic code, I would design a call-back mechanism for error handling, rather than propagating critical errors all over the place.
Yup, we have discussed this before, and perhaps most experts disagree with me, but my comment on error management in the draft on "Secure C Library Functions", did very much seem to have made it into the final "TR 24731 Part1: Bounce-checking interfaces".
http://groups.google.no/group/comp.std.c/browse_thread/thread/d340397fc9ac32f5/25af554fcc8ceeae?lnk=gst&q=Tor+Rustad&rnum=8&hl=no#25af554fcc8ceeae
Douglas A. Gwyn agreed with me, and some other experts must have too. :)
If you're writing the program itself, however, then of course you do whatever is the right thing for that program. But if my word processor exit()ed on a memory allocation failure without at least giving me the chance to save the last twenty minutes' typing, I'd be looking for a new word processor.
If a program need a save-data-and-terminate handler, such a thing can easily be added to a library. Propagating NULL, isn't the best way to go IMO.
--
Tor <torust [at] online [dot] no>
.
- References:
- Access violation in free()
- From: spl
- Re: Access violation in free()
- From: Martin Ambuhl
- Re: Access violation in free()
- From: Richard Heathfield
- Re: Access violation in free()
- From: Tor Rustad
- Re: Access violation in free()
- From: Richard Heathfield
- Access violation in free()
- Prev by Date: Re: size_t problems
- Next by Date: Re: size_t problems
- Previous by thread: Re: Access violation in free()
- Next by thread: Re: Access violation in free()
- Index(es):
Relevant Pages
|