From 2e500f08177e64c52915d988e862ae630826045f Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 2 Jun 2021 15:13:10 +0200 Subject: [PATCH 1/2] Check cairo status in draw_util_surface_free() When "something goes wrong" in cairo-land, the corresponding cairo object goes into an error state. These errors are sticky. Thus, it is enough to check for errors before destroying the context. This commit adds a check in draw_util_surface_free() to check the cairo context's status and print a log message if anything is wrong. The idea here is to help debugging drawing issues. Instead of "nothing visible", the corresponding log message hopefully helps debugging. This code would have saved me lots of time in figuring out why my pull request #4379 did not work. Signed-off-by: Uli Schlachter --- libi3/draw_util.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/libi3/draw_util.c b/libi3/draw_util.c index dd0900ceb..e698135d2 100644 --- a/libi3/draw_util.c +++ b/libi3/draw_util.c @@ -58,6 +58,19 @@ void draw_util_surface_init(xcb_connection_t *conn, surface_t *surface, xcb_draw * */ void draw_util_surface_free(xcb_connection_t *conn, surface_t *surface) { + cairo_status_t status = CAIRO_STATUS_SUCCESS; + if (surface->cr) { + status = cairo_status(surface->cr); + } + if (status != CAIRO_STATUS_SUCCESS) { + LOG("Found cairo context in an error status while freeing, error %d is %s", + status, cairo_status_to_string(status)); + } + + /* NOTE: This function is also called on uninitialised surface_t instances. + * The x11 error from xcb_free_gc(conn, XCB_NONE) is silently ignored + * elsewhere. + */ xcb_free_gc(conn, surface->gc); cairo_surface_destroy(surface->surface); cairo_destroy(surface->cr); From d2f5e7e46e430e7f9f9ca5244752e888c7c450e3 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 2 Jun 2021 15:17:52 +0200 Subject: [PATCH 2/2] Fix a minor memory leak When xcb_request_check() returns an error, something has to clean up and free this error. Signed-off-by: Uli Schlachter --- libi3/draw_util.c | 1 + 1 file changed, 1 insertion(+) diff --git a/libi3/draw_util.c b/libi3/draw_util.c index e698135d2..30eae656e 100644 --- a/libi3/draw_util.c +++ b/libi3/draw_util.c @@ -47,6 +47,7 @@ void draw_util_surface_init(xcb_connection_t *conn, surface_t *surface, xcb_draw xcb_generic_error_t *error = xcb_request_check(conn, gc_cookie); if (error != NULL) { ELOG("Could not create graphical context. Error code: %d. Please report this bug.\n", error->error_code); + free(error); } surface->surface = cairo_xcb_surface_create(conn, surface->id, visual, width, height);