summaryrefslogtreecommitdiffstats
path: root/src/mesa
diff options
context:
space:
mode:
authorAndres Rodriguez <[email protected]>2018-01-31 12:22:41 -0500
committerAndres Rodriguez <[email protected]>2018-02-01 09:48:04 -0500
commitbbd00844a2244cfe2702a5577a8d68f65877952a (patch)
treeda0782320b739beba526ebca6b0c683b4e659972 /src/mesa
parent2ef5ce11985c7ccd34887d00ab57e32d4036dbed (diff)
mesa: remove usage of alloca in externalobjects.c v4
Don't want an overly large numBufferBarriers/numTextureBarriers to blow up the stack. v2: handle malloc errors v3: fix patch v4: initialize texObjs/bufObjs Suggested-by: Emil Velikov <[email protected]> Signed-off-by: Andres Rodriguez <[email protected]>
Diffstat (limited to 'src/mesa')
-rw-r--r--src/mesa/main/externalobjects.c60
1 files changed, 48 insertions, 12 deletions
diff --git a/src/mesa/main/externalobjects.c b/src/mesa/main/externalobjects.c
index 463debd268a..35545c2e556 100644
--- a/src/mesa/main/externalobjects.c
+++ b/src/mesa/main/externalobjects.c
@@ -716,12 +716,14 @@ _mesa_WaitSemaphoreEXT(GLuint semaphore,
const GLenum *srcLayouts)
{
GET_CURRENT_CONTEXT(ctx);
- struct gl_semaphore_object *semObj;
- struct gl_buffer_object **bufObjs;
- struct gl_texture_object **texObjs;
+ struct gl_semaphore_object *semObj = NULL;
+ struct gl_buffer_object **bufObjs = NULL;
+ struct gl_texture_object **texObjs = NULL;
+
+ const char *func = "glWaitSemaphoreEXT";
if (!ctx->Extensions.EXT_semaphore) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glWaitSemaphoreEXT(unsupported)");
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
return;
}
@@ -734,12 +736,24 @@ _mesa_WaitSemaphoreEXT(GLuint semaphore,
FLUSH_VERTICES(ctx, 0);
FLUSH_CURRENT(ctx, 0);
- bufObjs = alloca(sizeof(struct gl_buffer_object **) * numBufferBarriers);
+ bufObjs = malloc(sizeof(struct gl_buffer_object **) * numBufferBarriers);
+ if (!bufObjs) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numBufferBarriers=%u)",
+ func, numBufferBarriers);
+ goto end;
+ }
+
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);
+ if (!texObjs) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numTextureBarriers=%u)",
+ func, numTextureBarriers);
+ goto end;
+ }
+
for (unsigned i = 0; i < numTextureBarriers; i++) {
texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
}
@@ -748,6 +762,10 @@ _mesa_WaitSemaphoreEXT(GLuint semaphore,
numBufferBarriers, bufObjs,
numTextureBarriers, texObjs,
srcLayouts);
+
+end:
+ free(bufObjs);
+ free(texObjs);
}
void GLAPIENTRY
@@ -759,12 +777,14 @@ _mesa_SignalSemaphoreEXT(GLuint semaphore,
const GLenum *dstLayouts)
{
GET_CURRENT_CONTEXT(ctx);
- struct gl_semaphore_object *semObj;
- struct gl_buffer_object **bufObjs;
- struct gl_texture_object **texObjs;
+ struct gl_semaphore_object *semObj = NULL;
+ struct gl_buffer_object **bufObjs = NULL;
+ struct gl_texture_object **texObjs = NULL;
+
+ const char *func = "glSignalSemaphoreEXT";
if (!ctx->Extensions.EXT_semaphore) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glSignalSemaphoreEXT(unsupported)");
+ _mesa_error(ctx, GL_INVALID_OPERATION, "%s(unsupported)", func);
return;
}
@@ -777,12 +797,24 @@ _mesa_SignalSemaphoreEXT(GLuint semaphore,
FLUSH_VERTICES(ctx, 0);
FLUSH_CURRENT(ctx, 0);
- bufObjs = alloca(sizeof(struct gl_buffer_object **) * numBufferBarriers);
+ bufObjs = malloc(sizeof(struct gl_buffer_object **) * numBufferBarriers);
+ if (!bufObjs) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numBufferBarriers=%u)",
+ func, numBufferBarriers);
+ goto end;
+ }
+
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);
+ if (!texObjs) {
+ _mesa_error(ctx, GL_OUT_OF_MEMORY, "%s(numTextureBarriers=%u)",
+ func, numTextureBarriers);
+ goto end;
+ }
+
for (unsigned i = 0; i < numTextureBarriers; i++) {
texObjs[i] = _mesa_lookup_texture(ctx, textures[i]);
}
@@ -791,6 +823,10 @@ _mesa_SignalSemaphoreEXT(GLuint semaphore,
numBufferBarriers, bufObjs,
numTextureBarriers, texObjs,
dstLayouts);
+
+end:
+ free(bufObjs);
+ free(texObjs);
}
void GLAPIENTRY