plug a DIR* leak on error path
authorDenys Vlasenko <vda.linux@googlemail.com>
Tue, 28 Dec 2010 09:25:03 +0000 (10:25 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Tue, 28 Dec 2010 09:25:03 +0000 (10:25 +0100)
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
libbb/find_root_device.c

index 32c86cea8e1de22f9262a74b91c24653e27fd416..8436cd664fcb28091299126baf82dfc5e3a59c4d 100644 (file)
@@ -29,14 +29,15 @@ static char *find_block_device_in_dir(struct arena *ap)
        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) {