<div dir="ltr">Patch didn't fix all leaks. There's one more still reported by ASAN:<div><br></div><div><span style="font-family:monospace"><span style="font-weight:bold;color:rgb(84,84,255)">Direct leak of 2112 byte(s) in 12 object(s) allocated from:</span><span style="color:rgb(0,0,0)"> </span><br>   #0 0x7fe18d168800 in calloc (/usr/lib/clang/3.9.1/lib/linux/<a href="http://libclang_rt.asan-x86_64.so">libclang_rt.asan-x86_64.so</a>+0xf6800)<span style="color:rgb(24,24,178)">                                                                                          </span><span style="color:rgb(0,0,0)"> </span><br>   #1 0x7fe181c141f6 in st_new_renderbuffer_fb /home/bartek/Devel/mesa/src/mesa/state_tracker/st_cb_fbo.c:277:11<br>
<br></span></div><div><span style="font-family:monospace"><br></span></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Apr 7, 2017 at 6:03 PM, Brian Paul <span dir="ltr"><<a href="mailto:brianp@vmware.com" target="_blank">brianp@vmware.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="HOEnZb"><div class="h5">On 04/06/2017 03:55 PM, Timothy Arceri wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
We don't need to call _mesa_reference_renderbuffer() for the first<br>
assignment as refCount starts at 1. For swrast we work around the<br>
fact we will indirectly call _mesa_reference_renderbuffer() by<br>
resetting refCount to 0.<br>
<br>
Fixes: 32141e53d1520 (mesa: tidy up renderbuffer RefCount initialisation)<br>
---<br>
  src/mesa/main/fbobject.c         | 2 +-<br>
  src/mesa/swrast/s_renderbuffer<wbr>.c | 5 +++++<br>
  2 files changed, 6 insertions(+), 1 deletion(-)<br>
<br>
diff --git a/src/mesa/main/fbobject.c b/src/mesa/main/fbobject.c<br>
index e52c1e3..e46a7ca 100644<br>
--- a/src/mesa/main/fbobject.c<br>
+++ b/src/mesa/main/fbobject.c<br>
@@ -441,21 +441,21 @@ _mesa_update_texture_renderbuf<wbr>fer(struct gl_context *ctx,<br>
<br>
     texImage = att->Texture->Image[att->CubeM<wbr>apFace][att->TextureLevel];<br>
<br>
     rb = att->Renderbuffer;<br>
     if (!rb) {<br>
        rb = ctx->Driver.NewRenderbuffer(ct<wbr>x, ~0);<br>
        if (!rb) {<br>
           _mesa_error(ctx, GL_OUT_OF_MEMORY, "glFramebufferTexture()");<br>
           return;<br>
        }<br>
-      _mesa_reference_renderbuffer(&<wbr>att->Renderbuffer, rb);<br>
+      att->Renderbuffer = rb;<br>
<br>
        /* This can't get called on a texture renderbuffer, so set it to NULL<br>
         * for clarity compared to user renderbuffers.<br>
         */<br>
        rb->AllocStorage = NULL;<br>
<br>
        rb->NeedsFinishRenderTexture = ctx->Driver.FinishRenderTextur<wbr>e != NULL;<br>
     }<br>
<br>
     if (!texImage)<br>
diff --git a/src/mesa/swrast/s_renderbuff<wbr>er.c b/src/mesa/swrast/s_renderbuff<wbr>er.c<br>
index d8c4ed3..af09955 100644<br>
--- a/src/mesa/swrast/s_renderbuff<wbr>er.c<br>
+++ b/src/mesa/swrast/s_renderbuff<wbr>er.c<br>
@@ -264,20 +264,25 @@ add_color_renderbuffers(struct gl_context *ctx, struct gl_framebuffer *fb,<br>
           continue;<br>
<br>
        assert(fb->Attachment[b].Rende<wbr>rbuffer == NULL);<br>
<br>
        rb = ctx->Driver.NewRenderbuffer(ct<wbr>x, 0);<br>
        if (!rb) {<br>
           _mesa_error(ctx, GL_OUT_OF_MEMORY, "Allocating color buffer");<br>
           return GL_FALSE;<br>
        }<br>
<br>
+      /* Set refcount to 0 to avoid a leak since the _mesa_add_renderbuffer()<br>
+       * call below will bump the initial refcount.<br>
+       */<br>
+      rb->RefCount = 0;<br>
+<br>
        rb->InternalFormat = GL_RGBA;<br>
<br>
        rb->AllocStorage = soft_renderbuffer_storage;<br>
        _mesa_add_renderbuffer(fb, b, rb);<br>
</blockquote>
<br></div></div>
Perhaps another way of doing this which wouldn't look quite so hacky would be to call _mesa_renderbuffer_reference(&<wbr>rb, NULL) here, after the _mesa_add_renderbuffer() call.  The idea is we're transferring ownership of the rb and the rb var is going out of scope.<br>
<br>
Something similar could be done above.  A comment indicating that we're transferring ownership could be helpful too.<br>
<br>
-Brian<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
     }<br>
<br>
     return GL_TRUE;<br>
  }<br>
<br>
<br>
<br>
</blockquote><div class="HOEnZb"><div class="h5">
<br>
______________________________<wbr>_________________<br>
mesa-dev mailing list<br>
<a href="mailto:mesa-dev@lists.freedesktop.org" target="_blank">mesa-dev@lists.freedesktop.org</a><br>
<a href="https://lists.freedesktop.org/mailman/listinfo/mesa-dev" rel="noreferrer" target="_blank">https://lists.freedesktop.org/<wbr>mailman/listinfo/mesa-dev</a><br>
</div></div></blockquote></div><br></div>