Avoid a segfault in shader compilation
authorRobert Ellison <papillo@vmware.com>
Mon, 27 Apr 2009 18:08:34 +0000 (12:08 -0600)
committerRobert Ellison <papillo@vmware.com>
Mon, 27 Apr 2009 18:11:24 +0000 (12:11 -0600)
If a shader reaches an out-of-memory condition while adding
a new function (reallocating the function list), a segfault
will occur during cleanup (because the num_functions field
is non-zero, but the functions pointer is NULL).

This fixes that segfault by zeroing out the num_functions
field if reallocation fails.

src/mesa/shader/slang/slang_compile.c

index ba2fc4f85c9c7bcc52071f2fdbc9598af167910b..d7ad879e97abcfaa4d4c4c502c7b460ed2535d13 100644 (file)
@@ -2161,6 +2161,12 @@ parse_function(slang_parse_ctx * C, slang_output_ctx * O, int definition,
                                            (O->funs->num_functions + 1)
                                            * sizeof(slang_function));
       if (O->funs->functions == NULL) {
+         /* Make sure that there are no functions marked, as the
+          * allocation is currently NULL, in order to avoid
+          * a potental segfault as we clean up later.
+          */
+         O->funs->num_functions = 0;
+
          slang_info_log_memory(C->L);
          slang_function_destruct(&parsed_func);
          return GL_FALSE;