[Mesa-dev] [PATCH 1/2] nouveau: avoid leaking fences while waiting

Ilia Mirkin imirkin at alum.mit.edu
Fri Nov 29 20:33:42 PST 2013

This fixes a memory leak in some situations. Also avoids emitting an
extra fence if the kick handler does the call to nouveau_fence_next

Signed-off-by: Ilia Mirkin <imirkin at alum.mit.edu>
Cc: "9.2 10.0" <mesa-stable at lists.freedesktop.org>

TBH I'm pretty confused by the whole fence refcounting logic and its
interaction with emits, updates, etc. However valgrind was happy with
this. But it wasn't happy when I was doing nouveau_fence_wait from
nv50_draw_elements, saying that the fence allocated by nouveau_fence_new was
leaked. (Note that the kick handler when doing vbo stuff does NOT do
nouveau_fence_next on its own... but adding that there still didn't fix all my
issues, nor is it likely desirable.)

 src/gallium/drivers/nouveau/nouveau_fence.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nouveau_fence.c b/src/gallium/drivers/nouveau/nouveau_fence.c
index dea146c..c686710 100644
--- a/src/gallium/drivers/nouveau/nouveau_fence.c
+++ b/src/gallium/drivers/nouveau/nouveau_fence.c
@@ -189,16 +189,15 @@ nouveau_fence_wait(struct nouveau_fence *fence)
    /* wtf, someone is waiting on a fence in flush_notify handler? */
    assert(fence->state != NOUVEAU_FENCE_STATE_EMITTING);
-   if (fence->state < NOUVEAU_FENCE_STATE_EMITTED) {
+   if (fence->state < NOUVEAU_FENCE_STATE_EMITTED)
-      if (fence == screen->fence.current)
-         nouveau_fence_new(screen, &screen->fence.current, FALSE);
-   }
-   if (fence->state < NOUVEAU_FENCE_STATE_FLUSHED) {
+   if (fence->state < NOUVEAU_FENCE_STATE_FLUSHED)
       if (nouveau_pushbuf_kick(screen->pushbuf, screen->pushbuf->channel))
          return FALSE;
-   }
+   if (fence == screen->fence.current)
+      nouveau_fence_next(screen);
    do {
       nouveau_fence_update(screen, FALSE);

More information about the mesa-dev mailing list