Skip to content

Commit c8bc9eb

Browse files
authored
glib_compat/glib_compact: Clear the buffer in g_hash_table_resize (#2219)
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. REF: intel/unicorn-for-efi#13 Signed-off-by: Chao Li <[email protected]> Signed-off-by: Dongyan Qian <[email protected]>
1 parent 3ad58e1 commit c8bc9eb

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)