From: Jean-Yves VET Date: Fri, 7 Aug 2020 13:49:36 +0000 (+0200) Subject: LU-13891 utils: fix memory leak in llapi_ladvise() X-Git-Tag: 2.13.57~49 X-Git-Url: https://git.whamcloud.com/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F10%2F39610%2F6;p=fs%2Flustre-release.git LU-13891 utils: fix memory leak in llapi_ladvise() 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 Change-Id: I0761e161074ae3029218473ec951670fdbbd33bd Reviewed-on: https://review.whamcloud.com/39610 Reviewed-by: Andreas Dilger Reviewed-by: Li Xi Reviewed-by: Jian Yu Tested-by: jenkins Tested-by: Maloo --- diff --git a/lustre/utils/liblustreapi_ladvise.c b/lustre/utils/liblustreapi_ladvise.c index c098889..6fd0209 100644 --- a/lustre/utils/liblustreapi_ladvise.c +++ b/lustre/utils/liblustreapi_ladvise.c @@ -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"); - return -1; + goto out; + } else { + rc = 0; } /* 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; } - return 0; +out: + free(ladvise_hdr); + return rc; }