nouveau: fix scratch buffer leak
authorMarcin Slusarz <marcin.slusarz@gmail.com>
Tue, 5 Jun 2012 21:26:05 +0000 (23:26 +0200)
committerMarcin Slusarz <marcin.slusarz@gmail.com>
Tue, 5 Jun 2012 21:58:43 +0000 (23:58 +0200)
...and create common function for destroying nouveau_context

src/gallium/drivers/nouveau/nouveau_context.h
src/gallium/drivers/nv30/nv30_context.c
src/gallium/drivers/nv50/nv50_context.c
src/gallium/drivers/nvc0/nvc0_context.c

index 531c623..b3fe05b 100644 (file)
@@ -2,6 +2,7 @@
 #define __NOUVEAU_CONTEXT_H__
 
 #include "pipe/p_context.h"
+#include <libdrm/nouveau.h>
 
 #define NOUVEAU_MAX_SCRATCH_BUFS 4
 
@@ -72,4 +73,15 @@ void *
 nouveau_scratch_get(struct nouveau_context *, unsigned size, uint64_t *gpu_addr,
                     struct nouveau_bo **);
 
+static INLINE void
+nouveau_context_destroy(struct nouveau_context *ctx)
+{
+   int i;
+
+   for (i = 0; i < NOUVEAU_MAX_SCRATCH_BUFS; ++i)
+      if (ctx->scratch.bo[i])
+         nouveau_bo_ref(NULL, &ctx->scratch.bo[i]);
+
+   FREE(ctx);
+}
 #endif
index b16cb23..42e844f 100644 (file)
@@ -92,7 +92,7 @@ nv30_context_destroy(struct pipe_context *pipe)
    if (nv30->screen->cur_ctx == nv30)
       nv30->screen->cur_ctx = NULL;
 
-   FREE(nv30);
+   nouveau_context_destroy(&nv30->base);
 }
 
 #define FAIL_CONTEXT_INIT(str, err)                   \
index 952dc03..cb9dd41 100644 (file)
@@ -111,7 +111,7 @@ nv50_destroy(struct pipe_context *pipe)
    draw_destroy(nv50->draw);
 #endif
 
-   FREE(nv50);
+   nouveau_context_destroy(&nv50->base);
 }
 
 struct pipe_context *
index f930814..b021f2e 100644 (file)
@@ -99,7 +99,7 @@ nvc0_destroy(struct pipe_context *pipe)
    draw_destroy(nvc0->draw);
 #endif
 
-   FREE(nvc0);
+   nouveau_context_destroy(&nvc0->base);
 }
 
 void