This avoids locking in the reference calls and fixes a leak after the
RefCount initialisation was change from 0 to 1.

Fixes: 32141e53d1520 (mesa: tidy up renderbuffer RefCount initialisation)
---
 src/mesa/drivers/dri/swrast/swrast.c |  6 ++++--
 src/mesa/swrast/s_renderbuffer.c     | 17 ++++++-----------
 2 files changed, 10 insertions(+), 13 deletions(-)

diff --git a/src/mesa/drivers/dri/swrast/swrast.c 
b/src/mesa/drivers/dri/swrast/swrast.c
index 0402232..f43ac60 100644
--- a/src/mesa/drivers/dri/swrast/swrast.c
+++ b/src/mesa/drivers/dri/swrast/swrast.c
@@ -562,26 +562,28 @@ dri_create_buffer(__DRIscreen * sPriv,
     if (drawable->row == NULL)
        goto drawable_fail;
 
     fb = &drawable->Base;
 
     /* basic framebuffer setup */
     _mesa_initialize_window_framebuffer(fb, visual);
 
     /* add front renderbuffer */
     frontrb = swrast_new_renderbuffer(visual, dPriv, GL_TRUE);
-    _mesa_add_renderbuffer(fb, BUFFER_FRONT_LEFT, &frontrb->Base.Base);
+    _mesa_add_renderbuffer_without_ref(fb, BUFFER_FRONT_LEFT,
+                                       &frontrb->Base.Base);
 
     /* add back renderbuffer */
     if (visual->doubleBufferMode) {
        backrb = swrast_new_renderbuffer(visual, dPriv, GL_FALSE);
-       _mesa_add_renderbuffer(fb, BUFFER_BACK_LEFT, &backrb->Base.Base);
+        _mesa_add_renderbuffer_without_ref(fb, BUFFER_BACK_LEFT,
+                                           &backrb->Base.Base);
     }
 
     /* add software renderbuffers */
     _swrast_add_soft_renderbuffers(fb,
                                    GL_FALSE, /* color */
                                    visual->haveDepthBuffer,
                                    visual->haveStencilBuffer,
                                    visual->haveAccumBuffer,
                                    GL_FALSE, /* alpha */
                                    GL_FALSE /* aux bufs */);
diff --git a/src/mesa/swrast/s_renderbuffer.c b/src/mesa/swrast/s_renderbuffer.c
index af09955..940c7b7 100644
--- a/src/mesa/swrast/s_renderbuffer.c
+++ b/src/mesa/swrast/s_renderbuffer.c
@@ -264,29 +264,24 @@ add_color_renderbuffers(struct gl_context *ctx, struct 
gl_framebuffer *fb,
          continue;
 
       assert(fb->Attachment[b].Renderbuffer == NULL);
 
       rb = ctx->Driver.NewRenderbuffer(ctx, 0);
       if (!rb) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating color buffer");
          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;
-      _mesa_add_renderbuffer(fb, b, rb);
+      _mesa_add_renderbuffer_without_ref(fb, b, rb);
    }
 
    return GL_TRUE;
 }
 
 
 /**
  * Add a software-based depth renderbuffer to the given framebuffer.
  * This is a helper routine for device drivers when creating a
  * window system framebuffer (not a user-created render/framebuffer).
@@ -318,21 +313,21 @@ add_depth_renderbuffer(struct gl_context *ctx, struct 
gl_framebuffer *fb,
       rb->InternalFormat = GL_DEPTH_COMPONENT16;
    }
    else if (depthBits <= 24) {
       rb->InternalFormat = GL_DEPTH_COMPONENT24;
    }
    else {
       rb->InternalFormat = GL_DEPTH_COMPONENT32;
    }
 
    rb->AllocStorage = soft_renderbuffer_storage;
-   _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
+   _mesa_add_renderbuffer_without_ref(fb, BUFFER_DEPTH, rb);
 
    return GL_TRUE;
 }
 
 
 /**
  * Add a software-based stencil renderbuffer to the given framebuffer.
  * This is a helper routine for device drivers when creating a
  * window system framebuffer (not a user-created render/framebuffer).
  * Once this function is called, you can basically forget about this
@@ -356,21 +351,21 @@ add_stencil_renderbuffer(struct gl_context *ctx, struct 
gl_framebuffer *fb,
    rb = _swrast_new_soft_renderbuffer(ctx, 0);
    if (!rb) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating stencil buffer");
       return GL_FALSE;
    }
 
    assert(stencilBits <= 8);
    rb->InternalFormat = GL_STENCIL_INDEX8;
 
    rb->AllocStorage = soft_renderbuffer_storage;
-   _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb);
+   _mesa_add_renderbuffer_without_ref(fb, BUFFER_STENCIL, rb);
 
    return GL_TRUE;
 }
 
 
 static GLboolean
 add_depth_stencil_renderbuffer(struct gl_context *ctx,
                                struct gl_framebuffer *fb)
 {
    struct gl_renderbuffer *rb;
@@ -380,21 +375,21 @@ add_depth_stencil_renderbuffer(struct gl_context *ctx,
 
    rb = _swrast_new_soft_renderbuffer(ctx, 0);
    if (!rb) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating depth+stencil buffer");
       return GL_FALSE;
    }
 
    rb->InternalFormat = GL_DEPTH_STENCIL;
 
    rb->AllocStorage = soft_renderbuffer_storage;
-   _mesa_add_renderbuffer(fb, BUFFER_DEPTH, rb);
+   _mesa_add_renderbuffer_without_ref(fb, BUFFER_DEPTH, rb);
    _mesa_add_renderbuffer(fb, BUFFER_STENCIL, rb);
 
    return GL_TRUE;
 }
 
 
 /**
  * Add a software-based accumulation renderbuffer to the given framebuffer.
  * This is a helper routine for device drivers when creating a
  * window system framebuffer (not a user-created render/framebuffer).
@@ -418,21 +413,21 @@ add_accum_renderbuffer(struct gl_context *ctx, struct 
gl_framebuffer *fb,
    assert(fb->Attachment[BUFFER_ACCUM].Renderbuffer == NULL);
 
    rb = _swrast_new_soft_renderbuffer(ctx, 0);
    if (!rb) {
       _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating accum buffer");
       return GL_FALSE;
    }
 
    rb->InternalFormat = GL_RGBA16_SNORM;
    rb->AllocStorage = soft_renderbuffer_storage;
-   _mesa_add_renderbuffer(fb, BUFFER_ACCUM, rb);
+   _mesa_add_renderbuffer_without_ref(fb, BUFFER_ACCUM, rb);
 
    return GL_TRUE;
 }
 
 
 
 /**
  * Add a software-based aux renderbuffer to the given framebuffer.
  * This is a helper routine for device drivers when creating a
  * window system framebuffer (not a user-created render/framebuffer).
@@ -463,21 +458,21 @@ add_aux_renderbuffers(struct gl_context *ctx, struct 
gl_framebuffer *fb,
 
       if (!rb) {
          _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating aux buffer");
          return GL_FALSE;
       }
 
       assert (colorBits <= 8);
       rb->InternalFormat = GL_RGBA;
 
       rb->AllocStorage = soft_renderbuffer_storage;
-      _mesa_add_renderbuffer(fb, BUFFER_AUX0 + i, rb);
+      _mesa_add_renderbuffer_without_ref(fb, BUFFER_AUX0 + i, rb);
    }
    return GL_TRUE;
 }
 
 
 /**
  * Create/attach software-based renderbuffers to the given framebuffer.
  * This is a helper routine for device drivers.  Drivers can just as well
  * call the individual _mesa_add_*_renderbuffer() routines directly.
  */
-- 
2.9.3

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to