From e3eaccb939836386aa5f5895eea0da3e9863826c Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sat, 5 Dec 2020 07:46:41 +0100 Subject: boilerplate-xcb: Avoid leaks on error Before this commit, running the test suite against a non-existing display under valgrind resulted in: $ ( cd test; DISPLAY=:2 CAIRO_TEST_TARGET=xcb valgrind --leak-check=full .libs/cairo-test-suite -f random-clip ) [...] ==47359== 64 bytes in 2 blocks are definitely lost in loss record 1 of 7 ==47359== at 0x483AB65: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so) ==47359== by 0x18A272: cairo_boilerplate_xcalloc (cairo-boilerplate-system.c:65) ==47359== by 0x18D652: _cairo_boilerplate_xcb_create_surface (cairo-boilerplate-xcb.c:269) ==47359== by 0x12906F: cairo_test_for_target (cairo-test.c:819) ==47359== by 0x12AAB5: _cairo_test_context_run_for_target (cairo-test.c:1555) ==47359== by 0x126921: _cairo_test_runner_draw (cairo-test-runner.c:250) ==47359== by 0x126921: main (cairo-test-runner.c:932) This commit fixes that by freeing the allocated memory in the error path. Signed-off-by: Uli Schlachter --- boilerplate/cairo-boilerplate-xcb.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'boilerplate') diff --git a/boilerplate/cairo-boilerplate-xcb.c b/boilerplate/cairo-boilerplate-xcb.c index cc9b422e9..e301d1299 100644 --- a/boilerplate/cairo-boilerplate-xcb.c +++ b/boilerplate/cairo-boilerplate-xcb.c @@ -276,6 +276,7 @@ _cairo_boilerplate_xcb_create_surface (const char *name, xtc->c = c = xcb_connect(NULL,NULL); if (c == NULL || xcb_connection_has_error(c)) { free (xtc); + free (info); return NULL; } @@ -309,12 +310,17 @@ _cairo_boilerplate_xcb_create_surface (const char *name, if (xcb_request_check (c, cookie) != NULL) { xcb_disconnect (c); free (xtc); + free (info); return NULL; } info->formats = xcb_render_query_pict_formats_reply (c, formats_cookie, 0); - if (info->formats == NULL) + if (info->formats == NULL) { + xcb_disconnect (c); + free (xtc); + free (info); return NULL; + } for (i = xcb_render_query_pict_formats_formats_iterator (info->formats); i.rem; -- cgit v1.2.1