Skip to content

Commit

Permalink
Fix memory issue when duplicate entry in map file
Browse files Browse the repository at this point in the history
The insertion of a map entry was mishandled when there is a
duplicate entry. The library routine actually takes care of
the situation by itself.
  • Loading branch information
tony-vanderpeet committed Feb 13, 2024
1 parent 66c0d0d commit cccc4fc
Showing 1 changed file with 3 additions and 17 deletions.
20 changes: 3 additions & 17 deletions schema.c
Original file line number Diff line number Diff line change
Expand Up @@ -716,23 +716,9 @@ sch_load_namespace_mappings (sch_instance *instance, const char *filename)
ns_names = g_strsplit (buf, " ", 2);
if (ns_names[0] && ns_names[1])
{
void *old_key;
void *old_value;

/* Look up this node name to check for duplicates. */
if (g_hash_table_lookup_extended (instance->map_hash_table, ns_names[0],
&old_key, &old_value))
{
g_hash_table_insert (instance->map_hash_table, g_strdup (ns_names[0]),
g_strdup (ns_names[1]));
g_free (old_key);
g_free (old_value);
}
else
{
g_hash_table_insert (instance->map_hash_table, g_strdup (ns_names[0]),
g_strdup (ns_names[1]));
}
/* Insert will take care of duplicates automatically. */
g_hash_table_insert (instance->map_hash_table, g_strdup (ns_names[0]),
g_strdup (ns_names[1]));
}
g_strfreev (ns_names);
}
Expand Down

0 comments on commit cccc4fc

Please sign in to comment.