plug a DIR* leak on error path
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
diff --git a/libbb/find_root_device.c b/libbb/find_root_device.c
index 32c86ce..8436cd6 100644
--- a/libbb/find_root_device.c
+++ b/libbb/find_root_device.c
@@ -29,14 +29,15 @@
char *retpath = NULL;
int len, rem;
- dir = opendir(ap->devpath);
- if (!dir)
- return NULL;
-
len = strlen(ap->devpath);
rem = DEVNAME_MAX-2 - len;
if (rem <= 0)
return NULL;
+
+ dir = opendir(ap->devpath);
+ if (!dir)
+ return NULL;
+
ap->devpath[len++] = '/';
while ((entry = readdir(dir)) != NULL) {