From 50ce29a3b59a8c2984a928ea062e0b415739724d Mon Sep 17 00:00:00 2001 From: Jean-Yves VET Date: Fri, 7 Aug 2020 15:49:36 +0200 Subject: [PATCH] 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 --- lustre/utils/liblustreapi_ladvise.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) 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; } -- 1.8.3.1