diff options
author | Uli Schlachter <psychon@znc.in> | 2020-12-05 07:46:41 +0100 |
---|---|---|
committer | Uli Schlachter <psychon@znc.in> | 2020-12-05 07:46:41 +0100 |
commit | e3eaccb939836386aa5f5895eea0da3e9863826c (patch) | |
tree | d81f2e3e91462bd9e1f17324a63f625b4f8026b2 /boilerplate | |
parent | f7054c892e35a04180d586e8af2d4c62601308f1 (diff) | |
download | cairo-e3eaccb939836386aa5f5895eea0da3e9863826c.tar.gz |
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 <psychon@znc.in>
Diffstat (limited to 'boilerplate')
-rw-r--r-- | boilerplate/cairo-boilerplate-xcb.c | 8 |
1 files changed, 7 insertions, 1 deletions
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; |