[PATCH v3 3/4] target/hexagon: idef-parser fix leak of init_list

Anton Johansson via posted 4 patches 6 months, 1 week ago
Maintainers: Alessandro Di Federico <ale@rev.ng>, Anton Johansson <anjo@rev.ng>
There is a newer version of this series
[PATCH v3 3/4] target/hexagon: idef-parser fix leak of init_list
Posted by Anton Johansson via 6 months, 1 week ago
gen_inst_init_args() is called for instructions using a predicate as an
rvalue. Upon first call, the list of arguments which might need
initialization init_list is freed to indicate that they have been
processed. For instructions without an rvalue predicate,
gen_inst_init_args() isn't called and init_list will never be freed.

Free init_list from free_instruction() if it hasn't already been freed.
A comment in free_instruction is also updated.

Signed-off-by: Anton Johansson <anjo@rev.ng>
Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com>
---
 target/hexagon/idef-parser/parser-helpers.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/target/hexagon/idef-parser/parser-helpers.c b/target/hexagon/idef-parser/parser-helpers.c
index 95f2b43076..c150c308be 100644
--- a/target/hexagon/idef-parser/parser-helpers.c
+++ b/target/hexagon/idef-parser/parser-helpers.c
@@ -2121,9 +2121,16 @@ void free_instruction(Context *c)
         g_string_free(g_array_index(c->inst.strings, GString*, i), TRUE);
     }
     g_array_free(c->inst.strings, TRUE);
+    /*
+     * Free list of arguments that might need initialization, if they haven't
+     * already been freed.
+     */
+    if (c->inst.init_list) {
+        g_array_free(c->inst.init_list, TRUE);
+    }
     /* Free INAME token value */
     g_string_free(c->inst.name, TRUE);
-    /* Free variables and registers */
+    /* Free declared TCGv variables */
     g_array_free(c->inst.allocated, TRUE);
     /* Initialize instruction-specific portion of the context */
     memset(&(c->inst), 0, sizeof(Inst));
-- 
2.45.0
Re: [PATCH v3 3/4] target/hexagon: idef-parser fix leak of init_list
Posted by Brian Cain 6 months, 1 week ago
On 5/21/2024 3:16 PM, Anton Johansson via wrote:
> gen_inst_init_args() is called for instructions using a predicate as an
> rvalue. Upon first call, the list of arguments which might need
> initialization init_list is freed to indicate that they have been
> processed. For instructions without an rvalue predicate,
> gen_inst_init_args() isn't called and init_list will never be freed.
>
> Free init_list from free_instruction() if it hasn't already been freed.
> A comment in free_instruction is also updated.
>
> Signed-off-by: Anton Johansson <anjo@rev.ng>
> Reviewed-by: Taylor Simpson <ltaylorsimpson@gmail.com>
> ---

Reviewed-by: Brian Cain <bcain@quicinc.com>

>   target/hexagon/idef-parser/parser-helpers.c | 9 ++++++++-
>   1 file changed, 8 insertions(+), 1 deletion(-)
>
> diff --git a/target/hexagon/idef-parser/parser-helpers.c b/target/hexagon/idef-parser/parser-helpers.c
> index 95f2b43076..c150c308be 100644
> --- a/target/hexagon/idef-parser/parser-helpers.c
> +++ b/target/hexagon/idef-parser/parser-helpers.c
> @@ -2121,9 +2121,16 @@ void free_instruction(Context *c)
>           g_string_free(g_array_index(c->inst.strings, GString*, i), TRUE);
>       }
>       g_array_free(c->inst.strings, TRUE);
> +    /*
> +     * Free list of arguments that might need initialization, if they haven't
> +     * already been freed.
> +     */
> +    if (c->inst.init_list) {
> +        g_array_free(c->inst.init_list, TRUE);
> +    }
>       /* Free INAME token value */
>       g_string_free(c->inst.name, TRUE);
> -    /* Free variables and registers */
> +    /* Free declared TCGv variables */
>       g_array_free(c->inst.allocated, TRUE);
>       /* Initialize instruction-specific portion of the context */
>       memset(&(c->inst), 0, sizeof(Inst));