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

Author: Yonggang Luo <[email protected]>
Date:   Sun Aug  7 22:33:50 2022 +0800

util: Fixes memory leak in u_printf_test.cpp

That's Fixes: bdc0a862 ("printf: add some unit tests")

Signed-off-by: Yonggang Luo <[email protected]>
Reviewed-by: Karol Herbst <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18024>

---

 src/util/tests/u_printf_test.cpp | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/src/util/tests/u_printf_test.cpp b/src/util/tests/u_printf_test.cpp
index 7dfce9c50f7..fe689958fa2 100644
--- a/src/util/tests/u_printf_test.cpp
+++ b/src/util/tests/u_printf_test.cpp
@@ -38,10 +38,8 @@ private:
    }
 
 protected:
-   u_memstream stream;
    char *out_buffer = nullptr;
    size_t buffer_size = 0;
-   FILE *out;
 
    struct format {
       std::vector<char> fmt;
@@ -54,13 +52,13 @@ protected:
 
    virtual void SetUp()
    {
-      u_memstream_open(&stream, &out_buffer, &buffer_size);
-      out = u_memstream_get(&stream);
    }
 
    virtual void TearDown()
    {
-      free(out_buffer);
+      if (out_buffer != NULL) {
+         free(out_buffer);
+      }
    }
 
    void add_format(const char *string, std::vector<unsigned> arg_sizes)
@@ -103,6 +101,10 @@ protected:
 
    std::string parse()
    {
+      u_memstream stream;
+      FILE* out;
+      u_memstream_open(&stream, &out_buffer, &buffer_size);
+      out = u_memstream_get(&stream);
       std::vector<u_printf_info> infos;
 
       for (auto& format : formats) {

Reply via email to