Don't leak form suggestions and don't return from the loop

This commit is contained in:
Christian Dywan 2009-10-07 23:04:30 +02:00
parent 37e2c84b2b
commit 0706bdbbe7

View file

@ -75,20 +75,26 @@ formhistory_prepare_js ()
static gchar* static gchar*
formhistory_build_js () formhistory_build_js ()
{ {
const gchar* suggestions = ""; gchar* suggestions = g_strdup ("");
GHashTableIter iter; GHashTableIter iter;
gpointer key, value; gpointer key, value;
gchar* script;
g_hash_table_iter_init (&iter, global_keys); g_hash_table_iter_init (&iter, global_keys);
while (g_hash_table_iter_next (&iter, &key, &value)) while (g_hash_table_iter_next (&iter, &key, &value))
suggestions = g_strdup_printf ("%s arr[\"%s\"] = [%s]; ", {
gchar* _suggestions = g_strdup_printf ("%s arr[\"%s\"] = [%s]; ",
suggestions, (char*)key, (char*)value); suggestions, (char*)key, (char*)value);
gchar* script = g_strdup_printf ("function FormSuggestions(eid) { " katze_assign (suggestions, _suggestions);
}
script = g_strdup_printf ("function FormSuggestions(eid) { "
"arr = new Array();" "arr = new Array();"
"%s" "%s"
"this.suggestions = arr[eid]; }" "this.suggestions = arr[eid]; }"
"%s", "%s",
suggestions, suggestions,
jsforms); jsforms);
g_free (suggestions);
return script; return script;
} }
@ -104,7 +110,7 @@ formhistory_update_main_hash (GHashTable* keys)
while (g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&value)) while (g_hash_table_iter_next (&iter, (gpointer)&key, (gpointer)&value))
{ {
if (value && *value && (strlen (value) > MAXCHARS || strlen (value) < MINCHARS)) if (value && *value && (strlen (value) > MAXCHARS || strlen (value) < MINCHARS))
return; continue;
tmp = g_hash_table_lookup (global_keys, (gpointer)key); tmp = g_hash_table_lookup (global_keys, (gpointer)key);
if (tmp) if (tmp)