[Qemu-devel] [PATCH 1/2] nbd/server: add additional assert to nbd_export_put

Vladimir Sementsov-Ogievskiy posted 2 patches 8 years, 3 months ago
[Qemu-devel] [PATCH 1/2] nbd/server: add additional assert to nbd_export_put
Posted by Vladimir Sementsov-Ogievskiy 8 years, 3 months ago
This place is not obvious, nbd_export_close may theoretically reduce
refcount to 0. It may happen if someone calls nbd_export_put on named
export not through nbd_export_set_name when refcount is 1.

Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
---
 nbd/server.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/nbd/server.c b/nbd/server.c
index 70b40ed27e..2f2e05943f 100644
--- a/nbd/server.c
+++ b/nbd/server.c
@@ -1179,6 +1179,7 @@ void nbd_export_put(NBDExport *exp)
         nbd_export_close(exp);
     }
 
+    assert(exp->refcount > 0);
     if (--exp->refcount == 0) {
         assert(exp->name == NULL);
         assert(exp->description == NULL);
-- 
2.11.1


Re: [Qemu-devel] [PATCH 1/2] nbd/server: add additional assert to nbd_export_put
Posted by Max Reitz 8 years, 2 months ago
On 2017-11-09 16:40, Vladimir Sementsov-Ogievskiy wrote:
> This place is not obvious, nbd_export_close may theoretically reduce
> refcount to 0. It may happen if someone calls nbd_export_put on named
> export not through nbd_export_set_name when refcount is 1.
> 
> Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@virtuozzo.com>
> ---
>  nbd/server.c | 1 +
>  1 file changed, 1 insertion(+)
Reviewed-by: Max Reitz <mreitz@redhat.com>