[Mesa-dev] [PATCH] mesa: remove usage of alloca in externalobjects.c v2

Andres Rodriguez andresx7 at gmail.com
Wed Jan 31 19:01:48 UTC 2018



On 2018-01-31 01:25 PM, Andres Rodriguez wrote:
> Don't want an overly large numBufferBarriers/numTextureBarriers to blow
> up the stack.
> 
> v2: handle malloc errors

Someone forgot to update his patch correctly before sending it out...

> 
> Suggested-by: Emil Velikov <emil.velikov at collabora.com>
> Signed-off-by: Andres Rodriguez <andresx7 at gmail.com>
> ---
>   src/mesa/main/externalobjects.c | 14 ++++++++++----
>   1 file changed, 10 insertions(+), 4 deletions(-)
> 
> diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
> index 463debd268..6a248f35a6 100644
> --- a/src/mesa/main/externalobjects.c
> +++ b/src/mesa/main/externalobjects.c
> @@ -727,34 +727,37 @@ _mesa_WaitSemaphoreEXT(GLuint semaphore,
>   
>      ASSERT_OUTSIDE_BEGIN_END(ctx);
>   
>      semObj = _mesa_lookup_semaphore_object(ctx, semaphore);
>      if (!semObj)
>         return;
>   
>      FLUSH_VERTICES(ctx, 0);
>      FLUSH_CURRENT(ctx, 0);
>   
> -   bufObjs = alloca(sizeof(struct gl_buffer_object **) * numBufferBarriers);
> +   bufObjs = malloc(sizeof(struct gl_buffer_object **) * numBufferBarriers);
>      for (unsigned i = 0; i < numBufferBarriers; i++) {
>         bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
>      }
>   
> -   texObjs = alloca(sizeof(struct gl_texture_object **) * numTextureBarriers);
> +   texObjs = malloc(sizeof(struct gl_texture_object **) * numTextureBarriers);
>      for (unsigned i = 0; i < numTextureBarriers; i++) {
>         texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
>      }
>   
>      ctx->Driver.ServerWaitSemaphoreObject(ctx, semObj,
>                                            numBufferBarriers, bufObjs,
>                                            numTextureBarriers, texObjs,
>                                            srcLayouts);
> +
> +   free(bufObjs);
> +   free(texObjs);
>   }
>   
>   void GLAPIENTRY
>   _mesa_SignalSemaphoreEXT(GLuint semaphore,
>                            GLuint numBufferBarriers,
>                            const GLuint *buffers,
>                            GLuint numTextureBarriers,
>                            const GLuint *textures,
>                            const GLenum *dstLayouts)
>   {
> @@ -770,34 +773,37 @@ _mesa_SignalSemaphoreEXT(GLuint semaphore,
>   
>      ASSERT_OUTSIDE_BEGIN_END(ctx);
>   
>      semObj = _mesa_lookup_semaphore_object(ctx, semaphore);
>      if (!semObj)
>         return;
>   
>      FLUSH_VERTICES(ctx, 0);
>      FLUSH_CURRENT(ctx, 0);
>   
> -   bufObjs = alloca(sizeof(struct gl_buffer_object **) * numBufferBarriers);
> +   bufObjs = malloc(sizeof(struct gl_buffer_object **) * numBufferBarriers);
>      for (unsigned i = 0; i < numBufferBarriers; i++) {
>         bufObjs[i] = _mesa_lookup_bufferobj(ctx, buffers[i]);
>      }
>   
> -   texObjs = alloca(sizeof(struct gl_texture_object **) * numTextureBarriers);
> +   texObjs = malloc(sizeof(struct gl_texture_object **) * numTextureBarriers);
>      for (unsigned i = 0; i < numTextureBarriers; i++) {
>         texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
>      }
>   
>      ctx->Driver.ServerSignalSemaphoreObject(ctx, semObj,
>                                              numBufferBarriers, bufObjs,
>                                              numTextureBarriers, texObjs,
>                                              dstLayouts);
> +
> +   free(bufObjs);
> +   free(texObjs);
>   }
>   
>   void GLAPIENTRY
>   _mesa_ImportMemoryFdEXT(GLuint memory,
>                           GLuint64 size,
>                           GLenum handleType,
>                           GLint fd)
>   {
>      GET_CURRENT_CONTEXT(ctx);
>   
> 


More information about the mesa-dev mailing list