diff mbox series

[v1,5/5] tests/plugins: make howvec clean-up after itself.

Message ID 20200207150118.23007-6-alex.bennee@linaro.org
State New
Headers show
Series plugins/next | expand

Commit Message

Alex Bennée Feb. 7, 2020, 3:01 p.m. UTC
TCG plugins are responsible for their own memory usage and although
the plugin_exit is tied to the end of execution in this case it is
still poor practice. Ensure we delete the hash table and related data
when we are done to be a good plugin citizen.

Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

---
 tests/plugin/howvec.c | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

-- 
2.20.1

Comments

Robert Foley Feb. 10, 2020, 7:34 p.m. UTC | #1
On Fri, 7 Feb 2020 at 10:01, Alex Bennée <alex.bennee@linaro.org> wrote:
>

> TCG plugins are responsible for their own memory usage and although

> the plugin_exit is tied to the end of execution in this case it is

> still poor practice. Ensure we delete the hash table and related data

> when we are done to be a good plugin citizen.

>

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>  tests/plugin/howvec.c | 12 +++++++++++-

>  static void plugin_exit(qemu_plugin_id_t id, void *p)

>  {

>      g_autoptr(GString) report = g_string_new("Instruction Classes:\n");

> @@ -213,12 +220,15 @@ static void plugin_exit(qemu_plugin_id_t id, void *p)

>          g_list_free(it);

>      }

>

> +    g_list_free(counts);

> +    g_hash_table_destroy(insns);

> +


Just one minor comment.  Seems like there might be an option to use
g_autoptr(GList) for counts.

Reviewed-by: Robert Foley <robert.foley@linaro.org>


>      qemu_plugin_outs(report->str);

>  }

>

>  static void plugin_init(void)

>  {

> -    insns = g_hash_table_new(NULL, g_direct_equal);

> +    insns = g_hash_table_new_full(NULL, g_direct_equal, NULL, &free_record);

>  }

>

>  static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata)

> --

> 2.20.1

>
Richard Henderson Feb. 11, 2020, 6:01 p.m. UTC | #2
On 2/7/20 7:01 AM, Alex Bennée wrote:
> TCG plugins are responsible for their own memory usage and although

> the plugin_exit is tied to the end of execution in this case it is

> still poor practice. Ensure we delete the hash table and related data

> when we are done to be a good plugin citizen.

> 

> Signed-off-by: Alex Bennée <alex.bennee@linaro.org>

> ---

>  tests/plugin/howvec.c | 12 +++++++++++-

>  1 file changed, 11 insertions(+), 1 deletion(-)


Reviewed-by: Richard Henderson <richard.henderson@linaro.org>



r~
diff mbox series

Patch

diff --git a/tests/plugin/howvec.c b/tests/plugin/howvec.c
index 4ca555e1239..7b77403559d 100644
--- a/tests/plugin/howvec.c
+++ b/tests/plugin/howvec.c
@@ -163,6 +163,13 @@  static gint cmp_exec_count(gconstpointer a, gconstpointer b)
     return ea->count > eb->count ? -1 : 1;
 }
 
+static void free_record(gpointer data)
+{
+    InsnExecCount *rec = (InsnExecCount *) data;
+    g_free(rec->insn);
+    g_free(rec);
+}
+
 static void plugin_exit(qemu_plugin_id_t id, void *p)
 {
     g_autoptr(GString) report = g_string_new("Instruction Classes:\n");
@@ -213,12 +220,15 @@  static void plugin_exit(qemu_plugin_id_t id, void *p)
         g_list_free(it);
     }
 
+    g_list_free(counts);
+    g_hash_table_destroy(insns);
+
     qemu_plugin_outs(report->str);
 }
 
 static void plugin_init(void)
 {
-    insns = g_hash_table_new(NULL, g_direct_equal);
+    insns = g_hash_table_new_full(NULL, g_direct_equal, NULL, &free_record);
 }
 
 static void vcpu_insn_exec_before(unsigned int cpu_index, void *udata)