<div dir="ltr">Hello, Eric.<div>Is that version of mem-leaks fix ok for you?</div></div><br><div class="gmail_quote"><div dir="ltr">On Mon, Jan 14, 2019 at 12:51 PM Sergii Romantsov <<a href="mailto:sergii.romantsov@gmail.com">sergii.romantsov@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Usage test 'depthstencil-render-miplevels 200 s=z24_s8' causes<br>
memory leaks.<br>
Fixed: memory allocation/deallocation is controlled more carefully.<br>
<br>
CC: Eric Anholt <<a href="mailto:eric@anholt.net" target="_blank">eric@anholt.net</a>><br>
Bugzilla: <a href="https://bugs.freedesktop.org/show_bug.cgi?id=108819" rel="noreferrer" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=108819</a><br>
Fixes: 7a0e61d7792f (depthstencil-render-miplevels: Present the results in non-auto mode.)<br>
Signed-off-by: Sergii Romantsov <<a href="mailto:sergii.romantsov@globallogic.com" target="_blank">sergii.romantsov@globallogic.com</a>><br>
---<br>
 tests/texturing/depthstencil-render-miplevels.cpp | 52 ++++++++++++++++++++---<br>
 1 file changed, 45 insertions(+), 7 deletions(-)<br>
<br>
diff --git a/tests/texturing/depthstencil-render-miplevels.cpp b/tests/texturing/depthstencil-render-miplevels.cpp<br>
index 9d4b42d..b9881d4 100644<br>
--- a/tests/texturing/depthstencil-render-miplevels.cpp<br>
+++ b/tests/texturing/depthstencil-render-miplevels.cpp<br>
@@ -109,9 +109,40 @@ bool attach_together = false;<br>
 bool attach_stencil_first = false;<br>
 GLenum depth_format;<br>
 int miplevel0_size;<br>
-int max_miplevel;<br>
-float **depth_miplevel_data;<br>
-uint8_t **stencil_miplevel_data;<br>
+int max_miplevel = 0;<br>
+float **depth_miplevel_data = NULL;<br>
+uint8_t **stencil_miplevel_data = NULL;<br>
+<br>
+static void<br>
+init_buffers()<br>
+{<br>
+       if (!depth_miplevel_data)<br>
+               depth_miplevel_data = (float **)calloc(max_miplevel + 1, sizeof(float *));<br>
+       if (!stencil_miplevel_data)<br>
+               stencil_miplevel_data = (uint8_t **)calloc(max_miplevel + 1,<br>
+                                                          sizeof(uint8_t *));<br>
+}<br>
+<br>
+static void<br>
+deinit_buffers()<br>
+{<br>
+       if (depth_miplevel_data)<br>
+       {<br>
+               for (int i = 0; i <= max_miplevel; ++i)<br>
+                       if (depth_miplevel_data[i])<br>
+                               free(depth_miplevel_data[i]);<br>
+               free(depth_miplevel_data);<br>
+               depth_miplevel_data = NULL;<br>
+       }<br>
+       if (stencil_miplevel_data)<br>
+       {<br>
+               for (int i = 0; i <= max_miplevel; ++i)<br>
+                       if (stencil_miplevel_data[i])<br>
+                               free(stencil_miplevel_data[i]);<br>
+               free(stencil_miplevel_data);<br>
+               stencil_miplevel_data = NULL;<br>
+       }<br>
+}<br>
<br>
 /**<br>
  * Check if the given depth/stencil/rgba texture internal format is supported.<br>
@@ -222,9 +253,11 @@ set_up_framebuffer_for_miplevel(int level)<br>
        GLenum status = glCheckFramebufferStatus(GL_DRAW_FRAMEBUFFER);<br>
        if (status == GL_FRAMEBUFFER_UNSUPPORTED && level == 0) {<br>
                printf("This buffer combination is unsupported\n");<br>
+               deinit_buffers();<br>
                piglit_report_result(PIGLIT_SKIP);<br>
        } else if (status != GL_FRAMEBUFFER_COMPLETE) {<br>
                printf("FBO incomplete at miplevel %d\n", level);<br>
+               deinit_buffers();<br>
                piglit_report_result(PIGLIT_FAIL);<br>
        }<br>
 }<br>
@@ -360,10 +393,6 @@ piglit_init(int argc, char **argv)<br>
        piglit_require_extension("GL_ARB_depth_texture");<br>
        piglit_require_extension("GL_ARB_texture_non_power_of_two");<br>
<br>
-       depth_miplevel_data = (float **)calloc(max_miplevel + 1, sizeof(float *));<br>
-       stencil_miplevel_data = (uint8_t **)calloc(max_miplevel + 1,<br>
-                                                  sizeof(uint8_t *));<br>
-<br>
        /* argv[2]: buffer combination */<br>
        if (strcmp(argv[2], "s=z24_s8") == 0) {<br>
                attach_stencil = true;<br>
@@ -510,7 +539,10 @@ render_results_to_screen()<br>
                                     GL_RED, GL_FLOAT,<br>
                                     depth_miplevel_data[level]);<br>
                        if (!piglit_check_gl_error(GL_NO_ERROR))<br>
+                       {<br>
+                               deinit_buffers();<br>
                                piglit_report_result(PIGLIT_FAIL);<br>
+                       }<br>
                }<br>
<br>
                render_tex_to_screen(tex, 0, 1);<br>
@@ -527,7 +559,10 @@ render_results_to_screen()<br>
                                     GL_RED, GL_UNSIGNED_BYTE,<br>
                                     stencil_miplevel_data[level]);<br>
                        if (!piglit_check_gl_error(GL_NO_ERROR))<br>
+                       {<br>
+                               deinit_buffers();<br>
                                piglit_report_result(PIGLIT_FAIL);<br>
+                       }<br>
                }<br>
<br>
                render_tex_to_screen(tex, miplevel0_size + 10, 1);<br>
@@ -572,6 +607,8 @@ piglit_display()<br>
                set_up_framebuffer_for_miplevel(level);<br>
                populate_miplevel(level);<br>
        }<br>
+<br>
+       init_buffers();<br>
        for (int level = 0; level <= max_miplevel; ++level) {<br>
                set_up_framebuffer_for_miplevel(level);<br>
                pass = test_miplevel(level) && pass;<br>
@@ -579,6 +616,7 @@ piglit_display()<br>
<br>
        if (!piglit_automatic)<br>
                render_results_to_screen();<br>
+       deinit_buffers();<br>
<br>
        return pass ? PIGLIT_PASS : PIGLIT_FAIL;<br>
 }<br>
-- <br>
2.7.4<br>
<br>
</blockquote></div>