diff mbox

[ndctl,2/5] ndctl: fix blk-ns test cleanup

Message ID 20160317005440.3025.71496.stgit@dwillia2-desk3.jf.intel.com (mailing list archive)
State Accepted
Commit eb6f9fbee8ab
Headers show

Commit Message

Dan Williams March 17, 2016, 12:54 a.m. UTC
ndctl_namespace_foreach_safe() needs to be used when a namespace is
deleted while iterating.  Otherwise, we can walk off into uninitialized
memory and segfault.

Reported-by: Ross Zwisler <ross.zwisler@linux.intel.com>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
---
 test/blk_namespaces.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
diff mbox

Patch

diff --git a/test/blk_namespaces.c b/test/blk_namespaces.c
index 968af2797feb..41c5ce0b1bd7 100644
--- a/test/blk_namespaces.c
+++ b/test/blk_namespaces.c
@@ -214,7 +214,7 @@  int test_blk_namespaces(int log_level)
 	char bdev[50];
 	struct ndctl_ctx *ctx;
 	struct ndctl_bus *bus;
-	struct ndctl_namespace *ndns[2];
+	struct ndctl_namespace *ndns[2], *_n;
 	struct ndctl_region *region, *blk_region = NULL;
 	struct ndctl_dimm *dimm;
 
@@ -307,7 +307,7 @@  int test_blk_namespaces(int log_level)
 
  err_cleanup:
 	if (blk_region) {
-		ndctl_namespace_foreach(blk_region, ndns[0])
+		ndctl_namespace_foreach_safe(blk_region, ndns[0], _n)
 			if (ndctl_namespace_get_size(ndns[0]) != 0)
 				disable_blk_namespace(ndns[0]);
 	}