mesa: fix renderbuffer leak
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 6 Apr 2017 21:55:17 +0000 (07:55 +1000)
committerTimothy Arceri <tarceri@itsqueeze.com>
Fri, 7 Apr 2017 09:48:10 +0000 (19:48 +1000)
We don't need to call _mesa_reference_renderbuffer() for the first
assignment as refCount starts at 1. For swrast we work around the
fact we will indirectly call _mesa_reference_renderbuffer() by
resetting refCount to 0.

Fixes: 32141e53d1520 (mesa: tidy up renderbuffer RefCount initialisation)
Reviewed-by: Samuel Iglesias Gonsálvez <siglesias@igalia.com>
src/mesa/main/fbobject.c
src/mesa/swrast/s_renderbuffer.c

index 3289f86803cc2414e5db521a5637bc4a2282c55a..d486d01195f0b9e0d03e71e99911af0958e65347 100644 (file)
@@ -451,7 +451,7 @@ _mesa_update_texture_renderbuffer(struct gl_context *ctx,
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()");
          return;
       }
-      _mesa_reference_renderbuffer(&att->Renderbuffer, rb);
+      att->Renderbuffer = rb;
 
       /* This can't get called on a texture renderbuffer, so set it to NULL
        * for clarity compared to user renderbuffers.
index d8c4ed3863881dec1cd7cb84d5755fd6b2f0d1b5..af09955484ec624f686f277d4f6c11f35891fa4e 100644 (file)
@@ -271,6 +271,11 @@ add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,
          return GL_FALSE;
       }
 
+      /* Set refcount to 0 to avoid a leak since the _mesa_add_renderbuffer()
+       * call below will bump the initial refcount.
+       */
+      rb->RefCount = 0;
+
       rb->InternalFormat = GL_RGBA;
 
       rb->AllocStorage = soft_renderbuffer_storage;