[Mesa-dev] [PATCH 2/3] mesa: Verify memory allocations success in _mesa_PushClientAttrib
Ian Romanick
idr at freedesktop.org
Tue Dec 3 08:46:34 PST 2013
On 12/02/2013 01:39 AM, Juha-Pekka Heikkila wrote:
> Check if any of the callocs fail and report it with _mesa_error
> if needed.
>
> Signed-off-by: Juha-Pekka Heikkila <juhapekka.heikkila at gmail.com>
> ---
> src/mesa/main/attrib.c | 34 ++++++++++++++++++++++++++++++----
> 1 file changed, 30 insertions(+), 4 deletions(-)
>
> diff --git a/src/mesa/main/attrib.c b/src/mesa/main/attrib.c
> index c9332bd..2418fb0 100644
> --- a/src/mesa/main/attrib.c
> +++ b/src/mesa/main/attrib.c
> @@ -1488,6 +1488,12 @@ init_array_attrib_data(struct gl_context *ctx,
> {
> /* Get a non driver gl_array_object. */
> attrib->ArrayObj = CALLOC_STRUCT( gl_array_object );
> +
> + if (attrib->ArrayObj == NULL) {
> + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib");
> + return;
> + }
> +
> _mesa_initialize_array_object(ctx, attrib->ArrayObj, 0);
> }
>
> @@ -1516,7 +1522,7 @@ _mesa_PushClientAttrib(GLbitfield mask)
> GET_CURRENT_CONTEXT(ctx);
>
> if (ctx->ClientAttribStackDepth >= MAX_CLIENT_ATTRIB_STACK_DEPTH) {
> - _mesa_error( ctx, GL_STACK_OVERFLOW, "glPushClientAttrib" );
> + _mesa_error(ctx, GL_STACK_OVERFLOW, "glPushClientAttrib");
In addition to Brian's comments, this is just spurious whitespace
changes. Don't mix formatting chages with substantive changes.
> return;
> }
>
> @@ -1529,10 +1535,19 @@ _mesa_PushClientAttrib(GLbitfield mask)
> struct gl_pixelstore_attrib *attr;
> /* packing attribs */
> attr = CALLOC_STRUCT( gl_pixelstore_attrib );
> + if (attr == NULL) {
> + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib");
> + goto end;
> + }
> copy_pixelstore(ctx, attr, &ctx->Pack);
> save_attrib_data(&head, GL_CLIENT_PACK_BIT, attr);
> /* unpacking attribs */
> attr = CALLOC_STRUCT( gl_pixelstore_attrib );
> + if (attr == NULL) {
> + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib");
> + goto end;
> + }
> +
> copy_pixelstore(ctx, attr, &ctx->Unpack);
> save_attrib_data(&head, GL_CLIENT_UNPACK_BIT, attr);
> }
> @@ -1540,13 +1555,24 @@ _mesa_PushClientAttrib(GLbitfield mask)
> if (mask & GL_CLIENT_VERTEX_ARRAY_BIT) {
> struct gl_array_attrib *attr;
> attr = CALLOC_STRUCT( gl_array_attrib );
> + if (attr == NULL) {
> + _mesa_error(ctx, GL_OUT_OF_MEMORY, "glPushClientAttrib");
> + goto end;
> + }
> +
> init_array_attrib_data(ctx, attr);
> + if (attr->ArrayObj == NULL) {
> + goto end;
> + }
> +
> save_array_attrib(ctx, attr, &ctx->Array);
> save_attrib_data(&head, GL_CLIENT_VERTEX_ARRAY_BIT, attr);
> }
> -
> - ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
> - ctx->ClientAttribStackDepth++;
> +end:
> + if (head != NULL) {
> + ctx->ClientAttribStack[ctx->ClientAttribStackDepth] = head;
> + ctx->ClientAttribStackDepth++;
> + }
> }
>
>
>
More information about the mesa-dev
mailing list