mirror of https://github.com/xemu-project/xemu.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 <mreitz@redhat.com> Signed-off-by: Jeff Cody <jcody@redhat.com> Signed-off-by: Kevin Wolf <kwolf@redhat.com>
This commit is contained in:
parent
58803ce74f
commit
9a4d5ca607
3
block.c
3
block.c
|
@ -5381,6 +5381,9 @@ void bdrv_ref(BlockDriverState *bs)
|
||||||
* deleted. */
|
* deleted. */
|
||||||
void bdrv_unref(BlockDriverState *bs)
|
void bdrv_unref(BlockDriverState *bs)
|
||||||
{
|
{
|
||||||
|
if (!bs) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
assert(bs->refcnt > 0);
|
assert(bs->refcnt > 0);
|
||||||
if (--bs->refcnt == 0) {
|
if (--bs->refcnt == 0) {
|
||||||
bdrv_delete(bs);
|
bdrv_delete(bs);
|
||||||
|
|
Loading…
Reference in New Issue