afs: Avoid memory leak on recursive write flock
authorAndrew Deason <adeason@sinenomine.net>
Fri, 1 Apr 2011 21:43:24 +0000 (16:43 -0500)
committerDerrick Brashear <shadow@dementia.org>
Sat, 2 Apr 2011 05:42:22 +0000 (22:42 -0700)
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.

Change-Id: I27c3df1d7807a0b74cba11d6e4a563df8232932a
Reviewed-on: http://gerrit.openafs.org/4395
Tested-by: BuildBot <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>

src/afs/VNOPS/afs_vnop_flock.c

index d7698f8..931a72c 100644 (file)
@@ -406,8 +406,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