Skip to content

Commit

Permalink
backend: dummy: do not leak owned pixmaps
Browse files Browse the repository at this point in the history
free pixmaps which ownership was transferred to the backend
  • Loading branch information
absolutelynothelix committed Jun 12, 2023
1 parent 1e398b9 commit 223872b
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/backend/dummy/dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ struct dummy_image {
xcb_pixmap_t pixmap;
bool transparent;
int *refcount;
bool owned;
UT_hash_handle hh;
};

Expand All @@ -42,6 +43,9 @@ void dummy_deinit(struct backend_base *data) {
log_warn("Backend image for pixmap %#010x is not freed", img->pixmap);
HASH_DEL(dummy->images, img);
free(img->refcount);
if (img->owned) {
xcb_free_pixmap(data->c, img->pixmap);
}
free(img);
}
free(dummy);
Expand Down Expand Up @@ -82,7 +86,7 @@ bool dummy_blur(struct backend_base *backend_data attr_unused, double opacity at
}

void *dummy_bind_pixmap(struct backend_base *base, xcb_pixmap_t pixmap,
struct xvisual_info fmt, bool owned attr_unused) {
struct xvisual_info fmt, bool owned) {
auto dummy = (struct dummy_data *)base;
struct dummy_image *img = NULL;
HASH_FIND_INT(dummy->images, &pixmap, img);
Expand All @@ -96,6 +100,7 @@ void *dummy_bind_pixmap(struct backend_base *base, xcb_pixmap_t pixmap,
img->transparent = fmt.alpha_size != 0;
img->refcount = ccalloc(1, int);
*img->refcount = 1;
img->owned = owned;

HASH_ADD_INT(dummy->images, pixmap, img);
return (void *)img;
Expand All @@ -112,6 +117,9 @@ void dummy_release_image(backend_t *base, void *image) {
if (*img->refcount == 0) {
HASH_DEL(dummy->images, img);
free(img->refcount);
if (img->owned) {
xcb_free_pixmap(base->c, img->pixmap);
}
free(img);
}
}
Expand Down

0 comments on commit 223872b

Please sign in to comment.