From Rich Felker, over IRC

diff --git a/policy.c b/policy.c
index c0d18a7e..78ad34cd 100644
--- a/policy.c
+++ b/policy.c
@@ -214,8 +214,9 @@ static char *disk_path(struct mdinfo *disk)
 				continue;
 			if (stb.st_rdev != makedev(disk->disk.major, disk->disk.minor))
 				continue;
+			char *result = xstrdup(ent->d_name);
 			closedir(by_path);
-			return xstrdup(ent->d_name);
+			return result;
 		}
 		closedir(by_path);
 	}
