Commit 8b632356 authored by Daiki Ueno's avatar Daiki Ueno
Browse files

Fix memleaks.

parent b8a01d79
......@@ -103,6 +103,7 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
GtkStyle *style;
GtkStateType state;
PangoContext *pcontext;
EekColor *color;
pcontext = gtk_widget_get_pango_context (self);
priv->renderer = eek_gtk_renderer_new (priv->keyboard, pcontext, self);
......@@ -114,12 +115,13 @@ eek_gtk_keyboard_real_draw (GtkWidget *self,
style = gtk_widget_get_style (self);
state = gtk_widget_get_state (self);
eek_renderer_set_foreground
(priv->renderer,
color_from_gdk_color (&style->fg[state]));
eek_renderer_set_background
(priv->renderer,
color_from_gdk_color (&style->bg[state]));
color = color_from_gdk_color (&style->fg[state]);
eek_renderer_set_foreground (priv->renderer, color);
eek_color_free (color);
color = color_from_gdk_color (&style->bg[state]);
eek_renderer_set_background (priv->renderer, color);
eek_color_free (color);
}
eek_renderer_render_keyboard (priv->renderer, cr);
......@@ -336,14 +338,10 @@ eek_gtk_keyboard_new (EekKeyboard *keyboard)
static EekColor *
color_from_gdk_color (GdkColor *gdk_color)
{
EekColor *color;
color = g_slice_new (EekColor);
color->red = gdk_color->red / (gdouble)0xFFFF;
color->green = gdk_color->green / (gdouble)0xFFFF;
color->blue = gdk_color->blue / (gdouble)0xFFFF;
color->alpha = 1.0;
return color;
return eek_color_new (gdk_color->red / (gdouble)0xFFFF,
gdk_color->green / (gdouble)0xFFFF,
gdk_color->blue / (gdouble)0xFFFF,
1.0);
}
static void
......
......@@ -99,6 +99,7 @@ eek_gtk_renderer_real_render_key_icon (EekRenderer *self,
eek_renderer_apply_transformation_for_key (self, cr, key, scale, rotate);
surface = pixbuf_to_cairo_surface (pixbuf);
g_object_unref (pixbuf);
cairo_set_source_surface (cr, surface, 0.0, 0.0);
cairo_paint (cr);
cairo_restore (cr);
......
......@@ -775,6 +775,8 @@ eek_keyboard_add_outline (EekKeyboard *keyboard,
_outline = eek_outline_copy (outline);
g_array_append_val (priv->outline_array, *_outline);
/* don't use eek_outline_free here, so as to keep _outline->points */
g_slice_free (EekOutline, _outline);
return priv->outline_array->len;
}
......
......@@ -380,6 +380,7 @@ render_key (EekRenderer *self,
cairo_fill (cr);
eek_renderer_render_key_outline (self, cr, key, 1.0, 0);
cairo_destroy (cr);
g_hash_table_insert (priv->outline_surface_cache,
outline,
......@@ -493,6 +494,7 @@ eek_renderer_real_render_key_label (EekRenderer *self,
}
pango_font_description_set_size (font, size * priv->scale * scale);
pango_layout_set_font_description (layout, font);
pango_font_description_free (font);
pango_layout_set_text (layout, label, -1);
pango_layout_set_width (layout,
PANGO_SCALE * bounds.width * priv->scale * scale);
......@@ -617,6 +619,9 @@ eek_renderer_finalize (GObject *object)
{
EekRendererPrivate *priv = EEK_RENDERER_GET_PRIVATE(object);
g_hash_table_destroy (priv->outline_surface_cache);
eek_color_free (priv->foreground);
eek_color_free (priv->background);
pango_font_description_free (priv->font);
G_OBJECT_CLASS (eek_renderer_parent_class)->finalize (object);
}
......@@ -658,12 +663,6 @@ eek_renderer_class_init (EekRendererClass *klass)
pspec);
}
static void
free_surface (gpointer data)
{
cairo_surface_destroy (data);
}
static void
eek_renderer_init (EekRenderer *self)
{
......@@ -681,7 +680,7 @@ eek_renderer_init (EekRenderer *self)
g_hash_table_new_full (g_direct_hash,
g_direct_equal,
NULL,
free_surface);
(GDestroyNotify)cairo_surface_destroy);
priv->keyboard_surface = NULL;
priv->symbol_index_changed_handler = 0;
}
......@@ -941,7 +940,9 @@ eek_renderer_set_foreground (EekRenderer *renderer,
g_return_if_fail (foreground);
priv = EEK_RENDERER_GET_PRIVATE(renderer);
priv->foreground = g_boxed_copy (EEK_TYPE_COLOR, foreground);
if (priv->foreground)
eek_color_free (priv->foreground);
priv->foreground = eek_color_copy (foreground);
}
void
......@@ -954,7 +955,9 @@ eek_renderer_set_background (EekRenderer *renderer,
g_return_if_fail (background);
priv = EEK_RENDERER_GET_PRIVATE(renderer);
priv->background = g_boxed_copy (EEK_TYPE_COLOR, background);
if (priv->background)
eek_color_free (priv->background);
priv->background = eek_color_copy (background);
}
void
......
......@@ -180,13 +180,13 @@ eek_outline_get_type (void)
}
/* EekColor */
static EekColor *
EekColor *
eek_color_copy (const EekColor *color)
{
return g_slice_dup (EekColor, color);
}
static void
void
eek_color_free (EekColor *color)
{
g_slice_free (EekColor, color);
......
......@@ -246,10 +246,12 @@ struct _EekColor
GType eek_color_get_type (void) G_GNUC_CONST;
EekColor *eek_color_new (gdouble red,
gdouble green,
gdouble blue,
gdouble alpha);
EekColor *eek_color_new (gdouble red,
gdouble green,
gdouble blue,
gdouble alpha);
EekColor *eek_color_copy (const EekColor *color);
void eek_color_free (EekColor *color);
G_END_DECLS
#endif /* EEK_TYPES_H */
......@@ -176,6 +176,7 @@ create_key (EekXkbLayout *layout,
}
}
oref = eek_keyboard_add_outline (keyboard, outline);
eek_outline_free (outline);
g_hash_table_insert (priv->shape_oref_hash, xkbshape, (gpointer)oref);
}
......
......@@ -388,6 +388,8 @@ eekboard_context_new (GDBusConnection *connection,
context_name_vanished_callback,
context,
NULL);
g_free (name_owner);
return context;
}
return NULL;
......
......@@ -162,6 +162,7 @@ eekboard_eekboard_new (GDBusConnection *connection,
eekboard_name_vanished_callback,
eekboard,
NULL);
g_free (name_owner);
return eekboard;
}
......
......@@ -574,6 +574,7 @@ set_keyboard (EekboardDesktopClient *client,
keyboard_name = g_strdup_printf ("keyboard%d", keyboard_serial++);
eek_element_set_name (EEK_ELEMENT(client->keyboard), keyboard_name);
g_free (keyboard_name);
keyboard_id = eekboard_context_add_keyboard (client->context,
client->keyboard,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment