Fix leak in test/bug-431.c

This test creates surfaces and patterns that it never cleans up. Found via
running:

  CAIRO_TEST_TARGET=image valgrind --leak-check=full ./cairo-test-suite -f bug-431

Output before this commit:

==21310==
==21310== HEAP SUMMARY:
==21310==     in use at exit: 569,788 bytes in 26 blocks
==21310==   total heap usage: 1,523 allocs, 1,497 frees, 2,034,252 bytes allocated
==21310==
==21310== 336 bytes in 2 blocks are definitely lost in loss record 5 of 17
==21310==    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==21310==    by 0x48BE2B0: _cairo_pattern_create_solid (cairo-pattern.c:614)
==21310==    by 0x48BE4B1: cairo_pattern_create_rgba (cairo-pattern.c:720)
==21310==    by 0x1358C6: draw (bug-431.c:50)
==21310==    by 0x129EDB: cairo_test_for_target (cairo-test.c:938)
==21310==    by 0x12B36A: _cairo_test_context_run_for_target (cairo-test.c:1545)
==21310==    by 0x12C370: _cairo_test_runner_draw (cairo-test-runner.c:258)
==21310==    by 0x12DEA0: main (cairo-test-runner.c:962)
==21310==
==21310== 278,534 (144 direct, 278,390 indirect) bytes in 1 blocks are definitely lost in loss record 15 of 17
==21310==    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==21310==    by 0x48BE51E: cairo_pattern_create_for_surface (cairo-pattern.c:756)
==21310==    by 0x135838: draw (bug-431.c:41)
==21310==    by 0x129EDB: cairo_test_for_target (cairo-test.c:938)
==21310==    by 0x12B36A: _cairo_test_context_run_for_target (cairo-test.c:1545)
==21310==    by 0x12C370: _cairo_test_runner_draw (cairo-test-runner.c:258)
==21310==    by 0x12DEA0: main (cairo-test-runner.c:962)
==21310==
==21310== 278,534 (144 direct, 278,390 indirect) bytes in 1 blocks are definitely lost in loss record 16 of 17
==21310==    at 0x48407B4: malloc (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==21310==    by 0x48BE51E: cairo_pattern_create_for_surface (cairo-pattern.c:756)
==21310==    by 0x488274D: _cairo_default_context_set_source_surface (cairo-default-context.c:327)
==21310==    by 0x49063DB: cairo_set_source_surface (cairo.c:977)
==21310==    by 0x1AC1DD: _cairo_boilerplate_get_image_surface (cairo-boilerplate.c:337)
==21310==    by 0x12A486: cairo_test_for_target (cairo-test.c:1145)
==21310==    by 0x12B36A: _cairo_test_context_run_for_target (cairo-test.c:1545)
==21310==    by 0x12C370: _cairo_test_runner_draw (cairo-test-runner.c:258)
==21310==    by 0x12DEA0: main (cairo-test-runner.c:962)
==21310==
==21310== LEAK SUMMARY:
==21310==    definitely lost: 624 bytes in 4 blocks
==21310==    indirectly lost: 556,780 bytes in 16 blocks
==21310==      possibly lost: 0 bytes in 0 blocks
==21310==    still reachable: 12,384 bytes in 6 blocks
==21310==         suppressed: 0 bytes in 0 blocks
==21310== Reachable blocks (those to which a pointer was found) are not shown.
==21310== To see them, rerun with: --leak-check=full --show-leak-kinds=all
==21310==
==21310== For lists of detected and suppressed errors, rerun with: -s
==21310== ERROR SUMMARY: 3 errors from 3 contexts (suppressed: 0 from 0)

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2023-09-17 12:26:19 +02:00
parent 7380d3dd7d
commit 14ae7c7fd2

View file

@ -53,6 +53,10 @@ draw (cairo_t *cr, int width, int height)
cairo_mask(cr, mask_pattern);
cairo_restore(cr);
cairo_surface_destroy (png_surface);
cairo_pattern_destroy (png_pattern);
cairo_pattern_destroy (mask_pattern);
return CAIRO_TEST_SUCCESS;
}