From 741bea05a3a5d170d47ca9df590f84ab02a7baad Mon Sep 17 00:00:00 2001 From: Andrew Deason Date: Fri, 1 Apr 2011 16:43:24 -0500 Subject: [PATCH] afs: Avoid memory leak on recursive write flock When a process requests an exclusive lock on a file on which it already holds an exclusive lock, we basically form a no-op. However, HandleFlock was allocating a new SimpleLocks and attaching it to avc->slocks, without freeing the old SimpleLocks structure. Since we don't need to do anything if we already hold an exclusive lock, just break out of the loop right away when we detect that scenario. Thus we avoid adding a new structure to avc->slocks, and we avoid a memory leak. Reviewed-on: http://gerrit.openafs.org/4395 Tested-by: BuildBot Reviewed-by: Derrick Brashear (cherry picked from commit ba9ae1ed7c269d7c080b5ce99b3b4bb2fe0a2a6f) Change-Id: I9e45a51e02774c555c6d5cb5ba9d0407b8442215 Reviewed-on: http://gerrit.openafs.org/5765 Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/afs/VNOPS/afs_vnop_flock.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/afs/VNOPS/afs_vnop_flock.c b/src/afs/VNOPS/afs_vnop_flock.c index f904d50c4..2eeb427c3 100644 --- a/src/afs/VNOPS/afs_vnop_flock.c +++ b/src/afs/VNOPS/afs_vnop_flock.c @@ -408,8 +408,14 @@ HandleFlock(struct vcache *avc, int acom, struct vrequest *areq, } else if (avc->flockCount == -1 && (acom & LOCK_EX)) { if (lockIdcmp2(&flock, avc, NULL, 1, clid)) { code = EWOULDBLOCK; - } else + } else { code = 0; + /* We've just re-grabbed an exclusive lock, so we don't + * need to contact the fileserver, and we don't need to + * add the lock to avc->slocks (since we already have a + * lock there). So, we are done. */ + break; + } } if (code == 0) { /* compatible here, decide if needs to go to file server. If -- 2.39.5