From 4fcb29a62bec4bdc9f227a4e3ae998c5f38eb74c Mon Sep 17 00:00:00 2001 From: Vertexwahn Date: Sun, 19 May 2024 23:16:41 +0200 Subject: [PATCH] Resolve issue of potential double free in test GitOrigin-RevId: 75d78221bf040035968680cfbde11d776db9800d --- .../imaging/tests/third_party/libpng_test.cpp | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/devertexwahn/imaging/tests/third_party/libpng_test.cpp b/devertexwahn/imaging/tests/third_party/libpng_test.cpp index 56b89da7..6985ddd3 100644 --- a/devertexwahn/imaging/tests/third_party/libpng_test.cpp +++ b/devertexwahn/imaging/tests/third_party/libpng_test.cpp @@ -39,20 +39,21 @@ TEST(libpng, load_png_test) { ASSERT_TRUE(false); } + else { + png_init_io(png_ptr, fp); - png_init_io(png_ptr, fp); + unsigned int sig_read = 0; + png_set_sig_bytes(png_ptr, sig_read); - unsigned int sig_read = 0; - png_set_sig_bytes(png_ptr, sig_read); + png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, png_voidp_NULL); - png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_STRIP_16 | PNG_TRANSFORM_PACKING | PNG_TRANSFORM_EXPAND, png_voidp_NULL); + int width = png_get_image_width(png_ptr, info_ptr); + int height = png_get_image_height(png_ptr, info_ptr); - int width = png_get_image_width(png_ptr, info_ptr); - int height = png_get_image_height(png_ptr, info_ptr); + EXPECT_THAT(width, 400); + EXPECT_THAT(height, 400); - EXPECT_THAT(width, 400); - EXPECT_THAT(height, 400); - - png_destroy_read_struct(&png_ptr, &info_ptr, nullptr); - fclose(fp); + png_destroy_read_struct(&png_ptr, &info_ptr, nullptr); + fclose(fp); + } }