Skip to contentSkip to conversation

plugins: Freeing allocated values in hash tables.

PATCH Applied Mahmoud Mandour 2 participants 5 messages Apr 21, 2021 – Apr 26, 2021

v1 of 2 Applied Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover plugins: Freeing allocated values in hash tables.

A hash table made using ``g_hash_table_new`` requires manually freeing any dynamically allocated keys/values. The two patches in this series fixes this issue in hotblocks and hotpages plugins.

Mahmoud Mandour (2):
plugins/hotblocks: Properly freed the hash table values plugins/hotpages: Properly freed the hash table values

 contrib/plugins/hotblocks.c | 3 ++-
 contrib/plugins/hotpages.c  | 3 ++-
 2 files changed, 4 insertions(+), 2 deletions(-)
Signature · 1 line
2.25.1
#1 lore raw

PATCH 1/2 plugins/hotblocks: Properly freed the hash table values

Freed the values stored in the hash table ``hotblocks`` returned by ``g_hash_table_get_values()`` by freeing the sorted list and destroyed the hash table afterward.

---
 contrib/plugins/hotblocks.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
contrib/plugins/hotblocks.c +2 -1
index 4b08340143..64692c0670 100644
@@ -68,10 +68,11 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
                                    rec->insns, rec->exec_count);
         }
 
-        g_list_free(it);
+        g_list_free_full(it, g_free);
         g_mutex_unlock(&lock);
     }
 
+    g_hash_table_destroy(hotblocks);
     qemu_plugin_outs(report->str);
 }
 
Signature · 1 line
2.25.1
#2 lore raw

PATCH 2/2 plugins/hotpages: Properly freed the hash table values

In reply to Mahmoud Mandour

Freed the values stored in the hash table ``pages`` returned by ``g_hash_table_get_values()`` by freeing the sorted list and destroyed the hash table afterward.

---
 contrib/plugins/hotpages.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
contrib/plugins/hotpages.c +2 -1
index bf53267532..2094ebd15f 100644
@@ -94,9 +94,10 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
                                    rec->cpu_read, rec->reads,
                                    rec->cpu_write, rec->writes);
         }
-        g_list_free(it);
+        g_list_free_full(it, g_free);
     }
 
+    g_hash_table_destroy(pages);
     qemu_plugin_outs(report->str);
 }
 
Signature · 1 line
2.25.1
Applied
#3 lore raw
In reply to Mahmoud Mandour
Quoted 3 lines · Mahmoud Mandour

A hash table made using ``g_hash_table_new`` requires manually freeing any dynamically allocated keys/values. The two patches in this series fixes this issue in hotblocks and hotpages plugins.

Queued to plugins/next, thanks.

Signature · 1 line
Alex Bennée
#4 lore raw
Quoted 7 lines · Alex Bennée
Quoted 3 lines · Mahmoud Mandour

A hash table made using ``g_hash_table_new`` requires manually freeing any dynamically allocated keys/values. The two patches in this series fixes this issue in hotblocks and hotpages plugins.

Queued to plugins/next, thanks.

Oops, dequeuing and applying v2 ;-)

Signature · 1 line
Alex Bennée