From 9a9800bbe9e2a38adaccc98314fff2354a52037e Mon Sep 17 00:00:00 2001 From: Jeffrey Cody Date: Tue, 16 Sep 2014 20:11:50 +0200 Subject: [PATCH 12/20] block: allow bdrv_unref() to be passed NULL pointers Message-id: Patchwork-id: 61216 O-Subject: [PATCH qemu-kvm-rhel RHEL7.1 11/15] block: allow bdrv_unref() to be passed NULL pointers Bugzilla: 1098086 RH-Acked-by: Fam Zheng RH-Acked-by: Stefan Hajnoczi RH-Acked-by: Max Reitz 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 (cherry picked from commit 9a4d5ca60772e09d0cbac01f1b4778aa68e00eaa) Signed-off-by: Miroslav Rezanina --- block.c | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/block.c b/block.c index a2e95f6..af162fe 100644 --- a/block.c +++ b/block.c @@ -5083,6 +5083,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); -- 1.7.1