My impression from the gdk docs is that gdk_color_copy
allocates memory:
Makes a copy of a color structure. The result must be freed using gdk_color_free().
The future-version gdk_rgba_copy
clearly does:
A newly allocated GdkRGBA, with the same contents as rgba
Nevertheless I am encountering memory errors in my code with the following (my_struct.color
is a GdkColor *
, initialized to NULL):
if (my_struct.color != NULL) {
gdk_color_free(my_struct.color);
}
my_struct.color = gdk_color_copy(color);
And the following appears to work:
if (my_struct.color == NULL) {
my_struct.color = malloc(sizeof(GdkColor));
}
memcpy(my_struct.color, color, sizeof(GdkColor));