From: Jeff Cody Date: Wed, 23 Jul 2014 21:22:57 +0000 (-0400) Subject: block: allow bdrv_unref() to be passed NULL pointers X-Git-Tag: qemu-xen-4.6.0-rc1~264^2~28 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9a4d5ca60772e09d0cbac01f1b4778aa68e00eaa;p=qemu-xen.git block: allow bdrv_unref() to be passed NULL pointers If bdrv_unref() is passed a NULL BDS pointer, it is safe to exit with no operation. This will allow cleanup code to blindly call bdrv_unref() on a BDS that has been initialized to NULL. Reviewed-by: Max Reitz Signed-off-by: Jeff Cody Signed-off-by: Kevin Wolf --- diff --git a/block.c b/block.c index 6b29285381..d7cb7d48fa 100644 --- a/block.c +++ b/block.c @@ -5381,6 +5381,9 @@ void bdrv_ref(BlockDriverState *bs) * deleted. */ void bdrv_unref(BlockDriverState *bs) { + if (!bs) { + return; + } assert(bs->refcnt > 0); if (--bs->refcnt == 0) { bdrv_delete(bs);