Fix memory leaks in swaybar

This commit is contained in:
Drew DeVault 2016-11-28 08:45:27 -05:00
parent de79fee777
commit cd5694fdb5
2 changed files with 7 additions and 3 deletions

View file

@ -94,6 +94,9 @@ static void destroy_buffer(struct buffer *buffer) {
if (buffer->surface) { if (buffer->surface) {
cairo_surface_destroy(buffer->surface); cairo_surface_destroy(buffer->surface);
} }
if (buffer->pango) {
g_object_unref(buffer->pango);
}
memset(buffer, 0, sizeof(struct buffer)); memset(buffer, 0, sizeof(struct buffer));
} }

View file

@ -10,12 +10,14 @@
PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text, PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text,
int32_t scale, bool markup) { int32_t scale, bool markup) {
PangoLayout *layout = pango_cairo_create_layout(cairo); PangoLayout *layout = pango_cairo_create_layout(cairo);
PangoAttrList *attrs = pango_attr_list_new(); PangoAttrList *attrs;
char *buf = malloc(2048);
if (markup) { if (markup) {
char *buf;
pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, NULL); pango_parse_markup(text, -1, 0, &attrs, &buf, NULL, NULL);
pango_layout_set_markup(layout, buf, -1); pango_layout_set_markup(layout, buf, -1);
free(buf);
} else { } else {
attrs = pango_attr_list_new();
pango_layout_set_text(layout, text, -1); pango_layout_set_text(layout, text, -1);
} }
pango_attr_list_insert(attrs, pango_attr_scale_new(scale)); pango_attr_list_insert(attrs, pango_attr_scale_new(scale));
@ -25,7 +27,6 @@ PangoLayout *get_pango_layout(cairo_t *cairo, const char *font, const char *text
pango_layout_set_attributes(layout, attrs); pango_layout_set_attributes(layout, attrs);
pango_attr_list_unref(attrs); pango_attr_list_unref(attrs);
pango_font_description_free(desc); pango_font_description_free(desc);
free(buf);
return layout; return layout;
} }