All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/2] plugins: Freeing allocated values in hash tables.
@ 2021-04-22  0:50 Mahmoud Mandour
  2021-04-22  0:50 ` [PATCH v2 1/2] plugins/hotblocks: Properly freed the hash table values Mahmoud Mandour
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Mahmoud Mandour @ 2021-04-22  0:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: 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.

v1 -> v2: Added a freeing function to hotpages instead of freeing
    the sorted list. That's probably better because the sorted list
    is only made on having ``counts != NULL`` and ``counts`` has a next
    pointer so essentially at least 2 elements in the list.

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(-)

-- 
2.25.1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH v2 1/2] plugins/hotblocks: Properly freed the hash table values
  2021-04-22  0:50 [PATCH v2 0/2] plugins: Freeing allocated values in hash tables Mahmoud Mandour
@ 2021-04-22  0:50 ` Mahmoud Mandour
  2021-04-22  0:50 ` [PATCH v2 2/2] plugins/hotpages: " Mahmoud Mandour
  2021-04-26 16:57 ` [PATCH v2 0/2] plugins: Freeing allocated values in hash tables Alex Bennée
  2 siblings, 0 replies; 4+ messages in thread
From: Mahmoud Mandour @ 2021-04-22  0:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mahmoud Mandour, Alex Bennée

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.

Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
---
 contrib/plugins/hotblocks.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/plugins/hotblocks.c b/contrib/plugins/hotblocks.c
index 4b08340143..64692c0670 100644
--- a/contrib/plugins/hotblocks.c
+++ b/contrib/plugins/hotblocks.c
@@ -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);
 }
 
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH v2 2/2] plugins/hotpages: Properly freed the hash table values
  2021-04-22  0:50 [PATCH v2 0/2] plugins: Freeing allocated values in hash tables Mahmoud Mandour
  2021-04-22  0:50 ` [PATCH v2 1/2] plugins/hotblocks: Properly freed the hash table values Mahmoud Mandour
@ 2021-04-22  0:50 ` Mahmoud Mandour
  2021-04-26 16:57 ` [PATCH v2 0/2] plugins: Freeing allocated values in hash tables Alex Bennée
  2 siblings, 0 replies; 4+ messages in thread
From: Mahmoud Mandour @ 2021-04-22  0:50 UTC (permalink / raw)
  To: qemu-devel; +Cc: Mahmoud Mandour, Alex Bennée

Allocated ``pages`` hash table through ``g_hash_table_new_full`` to
add a freeing function & destroyed the hash table on exit.

Signed-off-by: Mahmoud Mandour <ma.mandourr@gmail.com>
---
 contrib/plugins/hotpages.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/contrib/plugins/hotpages.c b/contrib/plugins/hotpages.c
index bf53267532..9cf7f02c77 100644
--- a/contrib/plugins/hotpages.c
+++ b/contrib/plugins/hotpages.c
@@ -97,13 +97,14 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)
         g_list_free(it);
     }
 
+    g_hash_table_destroy(pages);
     qemu_plugin_outs(report->str);
 }
 
 static void plugin_init(void)
 {
     page_mask = (page_size - 1);
-    pages = g_hash_table_new(NULL, g_direct_equal);
+    pages = g_hash_table_new_full(NULL, g_direct_equal, NULL, g_free);
 }
 
 static void vcpu_haddr(unsigned int cpu_index, qemu_plugin_meminfo_t meminfo,
-- 
2.25.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH v2 0/2] plugins: Freeing allocated values in hash tables.
  2021-04-22  0:50 [PATCH v2 0/2] plugins: Freeing allocated values in hash tables Mahmoud Mandour
  2021-04-22  0:50 ` [PATCH v2 1/2] plugins/hotblocks: Properly freed the hash table values Mahmoud Mandour
  2021-04-22  0:50 ` [PATCH v2 2/2] plugins/hotpages: " Mahmoud Mandour
@ 2021-04-26 16:57 ` Alex Bennée
  2 siblings, 0 replies; 4+ messages in thread
From: Alex Bennée @ 2021-04-26 16:57 UTC (permalink / raw)
  To: Mahmoud Mandour; +Cc: qemu-devel


Mahmoud Mandour <ma.mandourr@gmail.com> writes:

> 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.
>
> v1 -> v2: Added a freeing function to hotpages instead of freeing
>     the sorted list. That's probably better because the sorted list
>     is only made on having ``counts != NULL`` and ``counts`` has a next
>     pointer so essentially at least 2 elements in the list.

Queued to plugins/next, thanks.

-- 
Alex Bennée


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-04-26 16:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-22  0:50 [PATCH v2 0/2] plugins: Freeing allocated values in hash tables Mahmoud Mandour
2021-04-22  0:50 ` [PATCH v2 1/2] plugins/hotblocks: Properly freed the hash table values Mahmoud Mandour
2021-04-22  0:50 ` [PATCH v2 2/2] plugins/hotpages: " Mahmoud Mandour
2021-04-26 16:57 ` [PATCH v2 0/2] plugins: Freeing allocated values in hash tables Alex Bennée

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.