mirror of
				https://gitlab.gnome.org/GNOME/glib.git
				synced 2025-10-31 00:12:19 +01:00 
			
		
		
		
	g_settings_schema_list: some fixes
Prevent a crash in the case that gvdb_table_list() returns NULL (ie: because a schema has no keys). Stop a memory leak caused by pointlessly stealing keys from a hashtable (after we quarked them already). Stop allocating an extra entry at the end of an array for a terminator (that we never wrote anyway) when all functions using this API refer to the out-parameter length array. https://bugzilla.gnome.org/show_bug.cgi?id=711016
This commit is contained in:
		| @@ -1012,10 +1012,13 @@ g_settings_schema_list (GSettingsSchema *schema, | |||||||
|  |  | ||||||
|           list = gvdb_table_list (s->table, ""); |           list = gvdb_table_list (s->table, ""); | ||||||
|  |  | ||||||
|           for (i = 0; list[i]; i++) |           if (list) | ||||||
|             g_hash_table_add (items, list[i]); /* transfer ownership */ |             { | ||||||
|  |               for (i = 0; list[i]; i++) | ||||||
|  |                 g_hash_table_add (items, list[i]); /* transfer ownership */ | ||||||
|  |  | ||||||
|           g_free (list); /* free container only */ |               g_free (list); /* free container only */ | ||||||
|  |             } | ||||||
|         } |         } | ||||||
|  |  | ||||||
|       /* Do a first pass to eliminate child items that do not map to |       /* Do a first pass to eliminate child items that do not map to | ||||||
| @@ -1076,15 +1079,12 @@ g_settings_schema_list (GSettingsSchema *schema, | |||||||
|  |  | ||||||
|       /* Now create the list */ |       /* Now create the list */ | ||||||
|       len = g_hash_table_size (items); |       len = g_hash_table_size (items); | ||||||
|       schema->items = g_new (GQuark, len + 1); |       schema->items = g_new (GQuark, len); | ||||||
|       i = 0; |       i = 0; | ||||||
|       g_hash_table_iter_init (&iter, items); |       g_hash_table_iter_init (&iter, items); | ||||||
|  |  | ||||||
|       while (g_hash_table_iter_next (&iter, &name, NULL)) |       while (g_hash_table_iter_next (&iter, &name, NULL)) | ||||||
|         { |         schema->items[i++] = g_quark_from_string (name); | ||||||
|           schema->items[i++] = g_quark_from_string (name); |  | ||||||
|           g_hash_table_iter_steal (&iter); |  | ||||||
|         } |  | ||||||
|       schema->n_items = i; |       schema->n_items = i; | ||||||
|       g_assert (i == len); |       g_assert (i == len); | ||||||
|  |  | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user