Re: [PATCH -v3] futex: fix reference leak

Peter Zijlstra
2009-02-11T15:55:16Z

On Wed, 2009-02-11 at 16:49 +0100, Ingo Molnar wrote:
> * Peter Zijlstra <peterz@infradead.org> wrote:
>
> > So you prefer this version?
>
> yes, with s/out_unlock_put_key/err_unlock_put_key. That's the
> only error path that goes via the tail of the function, correct?

Right, but I think one can argue that most of the out* jumps are errors.

The only non-error return is the !unqueue_me() case.

Also, since there's only one user of out_unlock_put_key, we might also
do this:

---
Index: linux-2.6/kernel/futex.c
===================================================================
--- linux-2.6.orig/kernel/futex.c
+++ linux-2.6/kernel/futex.c
@@ -1220,8 +1220,10 @@ retry:
goto out;
}
ret = -EWOULDBLOCK;
- if (uval != val)
- goto out_unlock_put_key;
+ if (uval != val) {
+ queue_unlock(&q, hb);
+ goto out_put_key;
+ }

/* Only actually queue if *uaddr contained val. */
queue_me(&q, hb);
@@ -1319,10 +1321,6 @@ out_put_key:
put_futex_key(fshared, &q.key);
out:
return ret;
-
-out_unlock_put_key:
- queue_unlock(&q, hb);
- goto out_put_key;
}