mesa: remove usage of alloca in externalobjects.c

Submitted by Andres Rodriguez on Jan. 31, 2018, 5:30 p.m.

Details

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

Not browsing as part of any series.

Commit Message

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

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 31 January 2018 at 17:30, Andres Rodriguez <andresx7@gmail.com> wrote:
> Don't want an overly large numBufferBarriers/numTextureBarriers to blow
> up the stack.
>
> Suggested-by: Emil Velikov <emil.velikov@collabora.com>
> Signed-off-by: Andres Rodriguez <andresx7@gmail.com>
> ---
Thanks for sorting this Andres.

>  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);
Through the patch, please check for malloc failure and
_mesa_error(OOM)/free if so

-Emil