Plug a mem leak

The entity hashtable was leaking the keys.

==10167== 6 bytes in 1 blocks are definitely lost in loss record 19 of 155
==10167==    at 0x402AD89: malloc (vg_replace_malloc.c:236)
==10167==    by 0x4566BDA: standard_malloc (gmem.c:85)
==10167==    by 0x4566F80: g_malloc (gmem.c:159)
==10167==    by 0x457C89A: g_strdup (gstrfuncs.c:351)
==10167==    by 0x405774D: rsvg_entity_decl (rsvg-base.c:843)
parent d0d27dfd
......@@ -62,6 +62,23 @@ extern double rsvg_internal_dpi_y;
static GObjectClass *rsvg_parent_class = NULL;
static void
rsvg_ctx_free_entity (xmlEntityPtr entval)
{
#if LIBXML_VERSION < 20700
/* key == entval->name, so it's implicitly freed below */
xmlFree ((xmlChar *) entval->name);
xmlFree ((xmlChar *) entval->ExternalID);
xmlFree ((xmlChar *) entval->SystemID);
xmlFree (entval->content);
xmlFree (entval->orig);
xmlFree (entval);
#else
xmlFreeNode((xmlNode *) entval);
#endif
}
static void
instance_init (RsvgHandle * self)
{
......@@ -70,7 +87,10 @@ instance_init (RsvgHandle * self)
self->priv->flags = RSVG_HANDLE_FLAGS_NONE;
self->priv->defs = rsvg_defs_new ();
self->priv->handler_nest = 0;
self->priv->entities = g_hash_table_new (g_str_hash, g_str_equal);
self->priv->entities = g_hash_table_new_full (g_str_hash,
g_str_equal,
g_free,
(GDestroyNotify) rsvg_ctx_free_entity);
self->priv->dpi_x = rsvg_internal_dpi_x;
self->priv->dpi_y = rsvg_internal_dpi_y;
......@@ -91,25 +111,6 @@ instance_init (RsvgHandle * self)
self->priv->in_loop = FALSE;
}
static void
rsvg_ctx_free_helper (gpointer key, gpointer value, gpointer user_data)
{
xmlEntityPtr entval = (xmlEntityPtr) value;
#if LIBXML_VERSION < 20700
/* key == entval->name, so it's implicitly freed below */
xmlFree ((xmlChar *) entval->name);
xmlFree ((xmlChar *) entval->ExternalID);
xmlFree ((xmlChar *) entval->SystemID);
xmlFree (entval->content);
xmlFree (entval->orig);
xmlFree (entval);
#else
xmlFreeNode((xmlNode *) entval);
#endif
}
static void
instance_dispose (GObject * instance)
{
......@@ -120,7 +121,6 @@ instance_dispose (GObject * instance)
self->priv->is_disposed = TRUE;
g_hash_table_foreach (self->priv->entities, rsvg_ctx_free_helper, NULL);
g_hash_table_destroy (self->priv->entities);
rsvg_defs_free (self->priv->defs);
g_hash_table_destroy (self->priv->css_props);
......
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