diff --git a/NEWS b/NEWS
index d375acdd30e8ec95a4607b829fb90449a9af6c68..7f9737b054784b5a100c921fcf43ba7d5dc58e37 100644
--- a/NEWS
+++ b/NEWS
@@ -172,6 +172,7 @@ documents those changes that are of interest to users and administrators.
     data at slurmd startup.
  -- Integrate node_feature/knl_generic with "hbm" GRES information.
  -- Fix output routines to prevent rounding the TRES values for memory or BB.
+ -- switch/cray plugin - fix use after free error.
 
 * Changes in Slurm 16.05.6
 ==========================
diff --git a/src/plugins/switch/cray/util.c b/src/plugins/switch/cray/util.c
index 4ae70d34a87efe61fe9b2d46a5ae8e2e116356c9..cbb4f9f46a3973eaabcb5d28b434c9b1cda97b7d 100644
--- a/src/plugins/switch/cray/util.c
+++ b/src/plugins/switch/cray/util.c
@@ -63,8 +63,8 @@ int create_apid_dir(uint64_t apid, uid_t uid, gid_t gid)
 
 	rc = mkdir(apid_dir, 0700);
 	if (rc) {
-		xfree(apid_dir);
 		CRAY_ERR("mkdir failed to make directory %s: %m", apid_dir);
+		xfree(apid_dir);
 		return SLURM_ERROR;
 	}