From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([140.186.70.92]:48811) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rws2E-0001Pk-MW for qemu-devel@nongnu.org; Mon, 13 Feb 2012 04:17:28 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Rws28-0004fb-2B for qemu-devel@nongnu.org; Mon, 13 Feb 2012 04:17:22 -0500 Received: from mx1.redhat.com ([209.132.183.28]:38455) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Rws27-0004fI-Ql for qemu-devel@nongnu.org; Mon, 13 Feb 2012 04:17:15 -0500 Date: Mon, 13 Feb 2012 09:17:08 +0000 From: "Daniel P. Berrange" Message-ID: <20120213091708.GA32182@redhat.com> References: <1328884453-1067-1-git-send-email-zwu.kernel@gmail.com> <20120210144115.GI2914@redhat.com> <4F35635F.7070107@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <4F35635F.7070107@redhat.com> Subject: Re: [Qemu-devel] [PATCH] oslib: make error handling more reasonable Reply-To: "Daniel P. Berrange" List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Eric Blake Cc: Zhi Yong Wu , Zhi Yong Wu , qemu-devel@nongnu.org, stefanha@linux.vnet.ibm.com 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 :|