Whamcloud - gitweb
LU-13891 utils: fix memory leak in llapi_ladvise() 10/39610/6
authorJean-Yves VET <jyvet@ddn.com>
Fri, 7 Aug 2020 13:49:36 +0000 (15:49 +0200)
committerOleg Drokin <green@whamcloud.com>
Thu, 26 Nov 2020 09:26:10 +0000 (09:26 +0000)
A buffer allocated in llapi_ladvise() for ioctl() is never
released. This patch ensures the buffer is properly freed.

Fixes: e14246641c04 ("LU-4931 ladvise: Add feature of giving file access advices")
Signed-off-by: Jean-Yves VET <jyvet@ddn.com>
Change-Id: I0761e161074ae3029218473ec951670fdbbd33bd
Reviewed-on: https://review.whamcloud.com/39610
Reviewed-by: Andreas Dilger <adilger@whamcloud.com>
Reviewed-by: Li Xi <lixi@ddn.com>
Reviewed-by: Jian Yu <yujian@whamcloud.com>
Tested-by: jenkins <devops@whamcloud.com>
Tested-by: Maloo <maloo@whamcloud.com>
lustre/utils/liblustreapi_ladvise.c

index c098889..6fd0209 100644 (file)
@@ -78,7 +78,9 @@ int llapi_ladvise(int fd, unsigned long long flags, int num_advise,
        rc = ioctl(fd, LL_IOC_LADVISE, ladvise_hdr);
        if (rc < 0) {
                llapi_error(LLAPI_MSG_ERROR, -errno, "cannot give advice");
        rc = ioctl(fd, LL_IOC_LADVISE, ladvise_hdr);
        if (rc < 0) {
                llapi_error(LLAPI_MSG_ERROR, -errno, "cannot give advice");
-               return -1;
+               goto out;
+       } else {
+               rc = 0;
        }
 
        /* Copy results back in to caller provided structs */
        }
 
        /* Copy results back in to caller provided structs */
@@ -92,6 +94,8 @@ int llapi_ladvise(int fd, unsigned long long flags, int num_advise,
                                        ladvise_iter->lla_lockahead_result;
        }
 
                                        ladvise_iter->lla_lockahead_result;
        }
 
-       return 0;
+out:
+       free(ladvise_hdr);
+       return rc;
 }
 
 }