From: Ingo Molnar Subject: [PATCH] kvm tools: Fix segfault when running 'kvm' without a disk image Date: Fri, 8 Apr 2011 17:12:38 +0200 Message-ID: <20110408151238.GA13940@elte.hu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Cc: KVM devel mailing list To: Pekka Enberg Return-path: Received: from mx3.mail.elte.hu ([157.181.1.138]:41220 "EHLO mx3.mail.elte.hu" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752550Ab1DHPMm (ORCPT ); Fri, 8 Apr 2011 11:12:42 -0400 Content-Disposition: inline Sender: kvm-owner@vger.kernel.org List-ID: When running a simple, diskless 'kvm ./bzImage' KVM session we currently segfault at the end of the session: [ 4.895488] Kernel panic - not syncing: VFS: Unable to mount root fs on unknown-block(0,0) [ 4.899371] Rebooting in 1 seconds.. Program received signal SIGSEGV, Segmentation fault. disk_image__close (self=0x0) at disk-image.c:93 93 if (self->ops->close) (gdb) Because disk_image__close() assumes that 'self' is never NULL. Add a NULL check to allow a clean exit. Signed-off-by: Ingo Molnar --- tools/kvm/disk-image.c | 4 ++++ 1 files changed, 4 insertions(+), 0 deletions(-) diff --git a/tools/kvm/disk-image.c b/tools/kvm/disk-image.c index 80999c1..4099720 100644 --- a/tools/kvm/disk-image.c +++ b/tools/kvm/disk-image.c @@ -90,6 +90,10 @@ struct disk_image *disk_image__open(const char *filename) void disk_image__close(struct disk_image *self) { + /* If there was no disk image then there's nothing to do: */ + if (!self) + return; + if (self->ops->close) self->ops->close(self);