Whamcloud - gitweb
LU-17504 build: fix array-index-out-of-bounds warning
[fs/lustre-release.git] / lustre / utils / liblustreapi_util.c
index 9cb9c45..ceab7a4 100644 (file)
@@ -342,6 +342,7 @@ int llapi_rmfid(const char *path, struct fid_array *fa)
        }
 
        rc = llapi_rmfid_at(rootfd, fa);
+       close(rootfd);
        if (rc < 0) {
                fprintf(stderr, "lfs rmfid: cannot remove FIDs: %s\n",
                        strerror(-rc));
@@ -362,10 +363,15 @@ int llapi_direntry_remove(char *dname)
        int rc = 0;
 
        dirpath = strdup(dname);
-       namepath = strdup(dname);
-       if (!dirpath || !namepath)
+       if (!dirpath)
                return -ENOMEM;
 
+       namepath = strdup(dname);
+       if (!namepath) {
+               rc = -ENOMEM;
+               goto out_dirpath;
+       }
+
        filename = basename(namepath);
 
        dir = dirname(dirpath);
@@ -383,10 +389,10 @@ int llapi_direntry_remove(char *dname)
                            "error on ioctl %#lx for '%s' (%d)",
                            (long)LL_IOC_LMV_SETSTRIPE, filename, fd);
 out:
-       free(dirpath);
+       close(fd);
        free(namepath);
-       if (fd != -1)
-               close(fd);
+out_dirpath:
+       free(dirpath);
        return rc;
 #else
        return -EOPNOTSUPP;