term: free the data associated with the pixman image when destroying box-drawing glyphs

Closes #586
This commit is contained in:
Daniel Eklöf 2021-06-09 10:31:24 +02:00
parent a3f6c8ac78
commit cd37cdc940
No known key found for this signature in database
GPG key ID: 5BBD4992C116573F
2 changed files with 19 additions and 13 deletions

View file

@ -172,6 +172,9 @@
shifts (https://codeberg.org/dnkl/foot/issues/580).
* `TEXT`+`STRING`+`UTF8_STRING` mime types not being recognized in
clipboard offers (https://codeberg.org/dnkl/foot/issues/583).
* Memory leak caused by custom box drawing glyphs not being completely
freed when destroying a foot window instance
(https://codeberg.org/dnkl/foot/issues/586).
### Security

View file

@ -609,6 +609,18 @@ term_pt_or_px_as_pixels(const struct terminal *term,
: pt_or_px->px;
}
static void
free_box_drawing(struct fcft_glyph **box_drawing)
{
if (*box_drawing == NULL)
return;
free(pixman_image_get_data((*box_drawing)->pix));
pixman_image_unref((*box_drawing)->pix);
free(*box_drawing);
*box_drawing = NULL;
}
static bool
term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
{
@ -619,13 +631,8 @@ term_set_fonts(struct terminal *term, struct fcft_font *fonts[static 4])
term->fonts[i] = fonts[i];
}
for (size_t i = 0; i < ALEN(term->box_drawing); i++) {
if (term->box_drawing[i] != NULL) {
pixman_image_unref(term->box_drawing[i]->pix);
free(term->box_drawing[i]);
term->box_drawing[i] = NULL;
}
}
for (size_t i = 0; i < ALEN(term->box_drawing); i++)
free_box_drawing(&term->box_drawing[i]);
const int old_cell_width = term->cell_width;
const int old_cell_height = term->cell_height;
@ -1385,12 +1392,8 @@ term_destroy(struct terminal *term)
for (size_t i = 0; i < 4; i++)
free(term->font_sizes[i]);
for (size_t i = 0; i < ALEN(term->box_drawing); i++) {
if (term->box_drawing[i] != NULL) {
pixman_image_unref(term->box_drawing[i]->pix);
free(term->box_drawing[i]);
}
}
for (size_t i = 0; i < ALEN(term->box_drawing); i++)
free_box_drawing(&term->box_drawing[i]);
free(term->search.buf);