]> git.karo-electronics.de Git - karo-tx-linux.git/commitdiff
kvm tools: Fix segfault when running 'kvm' without a disk image
authorIngo Molnar <mingo@elte.hu>
Fri, 8 Apr 2011 15:12:38 +0000 (17:12 +0200)
committerPekka Enberg <penberg@kernel.org>
Fri, 8 Apr 2011 15:18:00 +0000 (18:18 +0300)
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 <mingo@elte.hu>
Signed-off-by: Pekka Enberg <penberg@kernel.org>
tools/kvm/disk-image.c

index 80999c13d505b9dd7b8beb48cc6ec3f749128807..4099720f13332db7e618ddc92f323c93524d6a1d 100644 (file)
@@ -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);