Module: Mesa
Branch: main
Commit: 49a6bdde8ef1da38df3f15e8478c8cad116eab46
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=49a6bdde8ef1da38df3f15e8478c8cad116eab46

Author: Michel Dänzer <[email protected]>
Date:   Wed Feb  8 17:36:35 2023 +0100

glsl/standalone: Do not pass memory allocated with ralloc_size to free

Pointed out by GCC:

In function ‘load_text_file’,
    inlined from ‘standalone_compile_shader’ at 
../src/compiler/glsl/standalone.cpp:491:38,
    inlined from ‘main’ at ../src/compiler/glsl/main.cpp:98:45:
../src/compiler/glsl/standalone.cpp:358:17: error: ‘free’ called on pointer 
‘block_195’ with nonzero offset 48 [-Werror=free-nonheap-object]
  358 |             free(text);
      |                 ^
In function ‘ralloc_size’,
    inlined from ‘load_text_file’ at ../src/compiler/glsl/standalone.cpp:352:31,
    inlined from ‘standalone_compile_shader’ at 
../src/compiler/glsl/standalone.cpp:491:38,
    inlined from ‘main’ at ../src/compiler/glsl/main.cpp:98:45:
../src/util/ralloc.c:117:18: note: returned from ‘malloc’
  117 |    void *block = malloc(align64(size + sizeof(ralloc_header),
      |                  ^

Fixes: a9696e79fb3a ("main: Close memory leak of shader string from 
load_text_file.")
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21215>

---

 src/compiler/glsl/standalone.cpp | 1 -
 1 file changed, 1 deletion(-)

diff --git a/src/compiler/glsl/standalone.cpp b/src/compiler/glsl/standalone.cpp
index b94ded29dfe..d33d5071f7b 100644
--- a/src/compiler/glsl/standalone.cpp
+++ b/src/compiler/glsl/standalone.cpp
@@ -355,7 +355,6 @@ load_text_file(void *ctx, const char *file_name)
          size_t bytes = fread(text + total_read,
                1, size - total_read, fp);
          if (bytes < size - total_read) {
-            free(text);
             text = NULL;
             goto error;
          }

Reply via email to