diff mbox

[2/3] daxctl_region_unref: fix a potential null pointer dereference

Message ID 20160623195950.30968-3-jmoyer@redhat.com (mailing list archive)
State New, archived
Headers show

Commit Message

Jeff Moyer June 23, 2016, 7:59 p.m. UTC
Move the assignment of ctx to after the NULL check.

Signed-off-by: Jeff Moyer <jmoyer@redhat.com>
---
 daxctl/lib/libdaxctl.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff mbox

Patch

diff --git a/daxctl/lib/libdaxctl.c b/daxctl/lib/libdaxctl.c
index a8ad58d..9d71a29 100644
--- a/daxctl/lib/libdaxctl.c
+++ b/daxctl/lib/libdaxctl.c
@@ -181,7 +181,7 @@  static void free_dev(struct daxctl_dev *dev, struct list_head *head)
 
 DAXCTL_EXPORT void daxctl_region_unref(struct daxctl_region *region)
 {
-	struct daxctl_ctx *ctx = region->ctx;
+	struct daxctl_ctx *ctx;
 	struct daxctl_dev *dev, *_d;
 
 	if (!region)
@@ -190,6 +190,7 @@  DAXCTL_EXPORT void daxctl_region_unref(struct daxctl_region *region)
 	if (region->refcount)
 		return;
 
+	ctx = region->ctx;
 	info(ctx, "region%d released\n", region->id);
 	list_for_each_safe(&region->devices, dev, _d, list)
 		free_dev(dev, &region->devices);