Mesa (master): Avoid a segfault in shader compilation

Robert Ellison papillo at kemper.freedesktop.org
Mon Apr 27 18:29:02 UTC 2009


Module: Mesa
Branch: master
Commit: 359a58230e0644a39c1904a74bc25803dc6cab6f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=359a58230e0644a39c1904a74bc25803dc6cab6f

Author: Robert Ellison <papillo at vmware.com>
Date:   Mon Apr 27 12:08:34 2009 -0600

Avoid a segfault in shader compilation

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 |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/src/mesa/shader/slang/slang_compile.c b/src/mesa/shader/slang/slang_compile.c
index ba2fc4f..d7ad879 100644
--- a/src/mesa/shader/slang/slang_compile.c
+++ b/src/mesa/shader/slang/slang_compile.c
@@ -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;




More information about the mesa-commit mailing list