diff mbox

[v3,1/5] block: allow bdrv_unref() to be passed NULL pointers

Message ID 19050483a76326d639013bb572cea80888c9c86d.1406150099.git.jcody@redhat.com
State New
Headers show

Commit Message

Jeff Cody July 23, 2014, 9:22 p.m. UTC
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>
---
 block.c | 3 +++
 1 file changed, 3 insertions(+)
diff mbox

Patch

diff --git a/block.c b/block.c
index 23f366d..f79efc8 100644
--- a/block.c
+++ b/block.c
@@ -5385,6 +5385,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);