block: allow bdrv_unref() to be passed NULL pointers
authorJeff Cody <jcody@redhat.com>
Wed, 23 Jul 2014 21:22:57 +0000 (17:22 -0400)
committerKevin Wolf <kwolf@redhat.com>
Fri, 15 Aug 2014 13:07:14 +0000 (15:07 +0200)
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 <mreitz@redhat.com>
Signed-off-by: Jeff Cody <jcody@redhat.com>
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
block.c

diff --git a/block.c b/block.c
index 6b29285381c8b7089666fdc5c90f6d5b504ea953..d7cb7d48faeb146efa6c28bbcf2f71e41a7b369c 100644 (file)
--- 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);