[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Qemu-devel] [PATCH] oslib: make error handling more reasonable
From: |
Daniel P. Berrange |
Subject: |
Re: [Qemu-devel] [PATCH] oslib: make error handling more reasonable |
Date: |
Mon, 13 Feb 2012 09:17:08 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
On Fri, Feb 10, 2012 at 11:35:11AM -0700, Eric Blake wrote:
> On 02/10/2012 07:41 AM, Daniel P. Berrange wrote:
>
> >> @@ -80,7 +80,7 @@ void *qemu_oom_check(void *ptr)
> >> {
> >> if (ptr == NULL) {
> >> fprintf(stderr, "Failed to allocate memory: %s\n",
> >> strerror(errno));
> >> - abort();
> >> + exit(EXIT_FAILURE);
> >
> > exit() will call any atexit()/on_exit() handlers, as well as trying
> > to flush I/O streams. Any of these actions may require further
> > memory allocations, which will likely fail, or worse cause this
> > code to re-enter itself if an atexit() handler calls qemu_malloc
> >
> > The only option other than abort(), is to use _Exit() which
> > doesn't try to run cleanup handlers.
>
> Correct, but in that case, then you need to fflush(stderr) prior to
> _Exit(), or else use write() rather than fprintf(), since otherwise your
> attempt at a nice oom error message is lost.
IIRC, stderr is not buffered, so should not need to be flushed.
Daniel
--
|: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :|
|: http://libvirt.org -o- http://virt-manager.org :|
|: http://autobuild.org -o- http://search.cpan.org/~danberr/ :|
|: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|