[Mesa-dev] [PATCH] [v2] meta: Plug memory leak

Kenneth Graunke kenneth at whitecape.org
Mon Mar 9 13:49:55 PDT 2015


On Monday, March 09, 2015 11:44:18 AM Ben Widawsky wrote:
> It looks like this has existed since
> commit f5a477ab76b6e0b268387699cd2253a43db0dfae
> Author: Ian Romanick <ian.d.romanick at intel.com>
> Date:   Mon Dec 16 11:54:08 2013 -0800
> 
>     meta: Refactor shader generation code out of mipmap generation path
> 
> Valgrind was complaining on fbo-generatemipmap-formats
> 
> v2: Instead, do the allocation after the early return block (v2)
> 
> Cc: Ian Romanick <ian.d.romanick at intel.com>
> Cc: Brian Paul <brianp at vmware.com>
> Cc: Eric Anholt <eric at anholt.net>
> Cc: Kenneth Graunke <kenneth at whitecape.org>
> Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
> ---
> 
> Thanks Ken. I wasn't sure if this path was common or not, and I had opted for
> the standard, define variables at the top, style. If it occurs more than
> infrequently, then I like this solution better.
> 
> (FYI: Jenkins results, http://otc-gfxtest-01.jf.intel.com/job/bwidawsk/100/)
> ---
>  src/mesa/drivers/common/meta.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
> 
> diff --git a/src/mesa/drivers/common/meta.c b/src/mesa/drivers/common/meta.c
> index fdc4cf1..fa800ec 100644
> --- a/src/mesa/drivers/common/meta.c
> +++ b/src/mesa/drivers/common/meta.c
> @@ -247,7 +247,6 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
>                               struct blit_shader_table *table)
>  {
>     char *vs_source, *fs_source;
> -   void *const mem_ctx = ralloc_context(NULL);
>     struct blit_shader *shader = choose_blit_shader(target, table);
>     const char *vs_input, *vs_output, *fs_input, *vs_preprocess, *fs_preprocess;
>  
> @@ -273,6 +272,8 @@ _mesa_meta_setup_blit_shader(struct gl_context *ctx,
>        return;
>     }
>  
> +   void *const mem_ctx = ralloc_context(NULL);
> +
>     vs_source = ralloc_asprintf(mem_ctx,
>                  "%s\n"
>                  "%s vec2 position;\n"
> 

I'm not clear whether we can get away with C99 mixed declarations and code yet
(in the past, it's been a problem for MSVC).  Assuming you move the
declaration back to the top, and leave the initialization here, this
would get a:

Reviewed-by: Kenneth Graunke <kenneth at whitecape.org>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: This is a digitally signed message part.
URL: <http://lists.freedesktop.org/archives/mesa-dev/attachments/20150309/fb8787c6/attachment-0001.sig>


More information about the mesa-dev mailing list