mesa: remove usage of alloca in externalobjects.c v2

Submitted by Andres Rodriguez on Jan. 31, 2018, 6:25 p.m.

Details

Message ID 20180131182556.5339-1-andresx7@gmail.com
State New
Headers show
Series "mesa: remove usage of alloca in externalobjects.c" ( rev: 2 ) in Mesa

Not browsing as part of any series.

Commit Message

Andres Rodriguez Jan. 31, 2018, 6:25 p.m.
Don't want an overly large numBufferBarriers/numTextureBarriers to blow
up the stack.

v2: handle malloc errors

Suggested-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
---
 src/mesa/main/externalobjects.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Patch hide | download patch | download mbox

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);
 

Comments

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@collabora.com>
> Signed-off-by: Andres Rodriguez <andresx7@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);
>   
>