Fix memory leak in color palette due to missing dispose function

This commit is contained in:
Mario Hüttel 2019-08-19 19:52:50 +02:00
parent c2323ab43d
commit 0d0b692960

View File

@ -35,6 +35,7 @@ struct _ColorPalette {
/** @brief The length of the _ColorPalette::color_array array */ /** @brief The length of the _ColorPalette::color_array array */
unsigned int color_array_length; unsigned int color_array_length;
/* Dummy bytes to ensure ABI compatibility in future versions */
gpointer dummy[4]; gpointer dummy[4];
}; };
@ -116,8 +117,8 @@ static int color_palette_fill_with_resource(ColorPalette *palette, char *resourc
palette->color_array = (GdkRGBA *)malloc(sizeof(GdkRGBA) * (unsigned int)lines); palette->color_array = (GdkRGBA *)malloc(sizeof(GdkRGBA) * (unsigned int)lines);
/* Setup regex for hexadecimal RGB colors like 'A0CB3F' */ /* Setup regex for hexadecimal RGB colors like 'A0CB3F' */
regex = g_regex_new("^(?<red>[0-9A-Fa-f][0-9A-Fa-f])(?<green>[0-9A-Fa-f][0-9A-Fa-f])(?<blue>[0-9A-Fa-f][0-9A-Fa-f])$", 0, 0, NULL); regex = g_regex_new("^(?<red>[0-9A-Fa-f][0-9A-Fa-f])(?<green>[0-9A-Fa-f][0-9A-Fa-f])(?<blue>[0-9A-Fa-f][0-9A-Fa-f])$",
0, 0, NULL);
/* Reset line */ /* Reset line */
line_idx = 0; line_idx = 0;
@ -227,11 +228,27 @@ unsigned int color_palette_get_color_count(ColorPalette *palette)
return return_val; return return_val;
} }
static void color_palette_dispose(GObject *gobj)
{
ColorPalette *palette;
palette = GDS_RENDER_COLOR_PALETTE(gobj);
if (palette->color_array)
{
palette->color_array_length = 0;
free(palette->color_array);
}
/* Chain up to parent class */
G_OBJECT_CLASS(color_palette_parent_class)->dispose(gobj);
}
static void color_palette_class_init(ColorPaletteClass *klass) static void color_palette_class_init(ColorPaletteClass *klass)
{ {
(void)klass; GObjectClass *gclass;
/* Nothing to do for now */
return; gclass = G_OBJECT_CLASS(klass);
gclass->dispose = color_palette_dispose;
} }
static void color_palette_init(ColorPalette *self) static void color_palette_init(ColorPalette *self)