[LU-13891] ladvise: buffer allocated for ioctl is never released Created: 07/Aug/20  Updated: 26/Nov/20  Resolved: 26/Nov/20

Status: Resolved
Project: Lustre
Component/s: None
Affects Version/s: Lustre 2.14.0, Lustre 2.12.6
Fix Version/s: Lustre 2.14.0

Type: Bug Priority: Minor
Reporter: Jean-Yves Vet (Inactive) Assignee: Jean-Yves Vet (Inactive)
Resolution: Fixed Votes: 0
Labels: patch

Attachments: File 0001-LU-13891-ladvise-Fix-a-memory-leak.patch    
Rank (Obsolete): 9223372036854775807

 Description   

There is a memory leak in the llapi_ladvise function. ladvise_hdr is never freed. 



 Comments   
Comment by Jean-Yves Vet (Inactive) [ 07/Aug/20 ]

I'll submit a very small fix shortly. 

Comment by Jean-Yves Vet (Inactive) [ 07/Aug/20 ]

Sorry, I don't have any account on review.whamcloud.com (same with id.whamcloud.com). I'll attach the patch to this ticket. 

Comment by Andreas Dilger [ 07/Aug/20 ]

Hi Jean-Yves, thanks for the patch. I'm just asking about an account for you.

 	rc = ioctl(fd, LL_IOC_LADVISE, ladvise_hdr);
 	if (rc < 0) {
+		free(ladvise_hdr);
 		llapi_error(LLAPI_MSG_ERROR, -errno, "cannot give advice");
 		return -1;
 	}
@@ -92,6 +93,7 @@ int llapi_ladvise(int fd, unsigned long long flags, int num_advise,
 					ladvise_iter->lla_lockahead_result;
 	}
 
+	free(ladvise_hdr);
 	return 0;
 }

It is preferred to have the error case use a goto and have only a single free() call at the end. Usig a single cleanup path avoids duplicate logic at each error site, and avoids similar leaks in the future.

Comment by Jean-Yves Vet (Inactive) [ 10/Aug/20 ]

Hi Andreas, thanks for the review! Peter Jones kindly helped. I can now log in to gerrit. I've modified the patch and will push for review the new version as soon as I get push permissions set. 

Comment by Gerrit Updater [ 10/Aug/20 ]

Jean-Yves Vet (contact@jean-yves.vet) uploaded a new patch: https://review.whamcloud.com/39610
Subject: LU-13891 ladvise: Fix a memory leak
Project: fs/lustre-release
Branch: master
Current Patch Set: 1
Commit: 1cac9d5772fdaf5d9c10e30dfbe40ec14ac7e321

Comment by Gerrit Updater [ 26/Nov/20 ]

Oleg Drokin (green@whamcloud.com) merged in patch https://review.whamcloud.com/39610/
Subject: LU-13891 utils: fix memory leak in llapi_ladvise()
Project: fs/lustre-release
Branch: master
Current Patch Set:
Commit: 50ce29a3b59a8c2984a928ea062e0b415739724d

Comment by Peter Jones [ 26/Nov/20 ]

Landed for 2.14

Generated at Sat Feb 10 03:05:05 UTC 2024 using Jira 9.4.14#940014-sha1:734e6822bbf0d45eff9af51f82432957f73aa32c.