Skip to content
This repository was archived by the owner on Mar 25, 2025. It is now read-only.

Commit 1af4411

Browse files
committed
glib_compat/glib_compact: Clear the buffer in g_hash_table_resize
There has a hidden danger in g_hash_table_resize function: The g_hash_table_resize, it seems to resize the has table, and write the old value to the new hash table. It seems look for the empty items in the new_nodes, and if the new_nodes is not be cleared, it maybe naver found the empty items. So I added a line under the g_new0 function, and I think clearing new_nodes every time may improve the performance. Added a memset to clear the new_nodes to fix this problem. Signed-off-by: Chao Li <lichao@loongson.cn>
1 parent 6acd078 commit 1af4411

File tree

1 file changed

+1
-0
lines changed

1 file changed

+1
-0
lines changed

glib_compat/glib_compat.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,6 +716,7 @@ static void g_hash_table_resize (GHashTable *hash_table)
716716
g_hash_table_set_shift_from_size (hash_table, hash_table->nnodes * 2);
717717

718718
new_nodes = g_new0 (GHashNode, hash_table->size);
719+
memset(new_nodes, 0, hash_table->size * sizeof(GHashNode));
719720

720721
for (i = 0; i < old_size; i++)
721722
{

0 commit comments

Comments
 (0)