[template-glib] expr-parser.y: free allocated strings when parsing



commit f0a25ddb898c0d8b75b5a93ffe84ed7c0955784d
Author: Christian Hergert <chergert redhat com>
Date:   Wed May 4 13:05:11 2022 -0700

    expr-parser.y: free allocated strings when parsing
    
    These are not handled automatically for us, and most TmplExpr node creation
    take `const char *` strings and therefore are not freeing these for us.
    
    An oversight I wish we could fix for parsing performance, but what can you
    do at this point.

 src/tmpl-expr-parser.y | 12 ++++++++++++
 1 file changed, 12 insertions(+)
---
diff --git a/src/tmpl-expr-parser.y b/src/tmpl-expr-parser.y
index 033fbf4..f2da6fd 100644
--- a/src/tmpl-expr-parser.y
+++ b/src/tmpl-expr-parser.y
@@ -166,45 +166,57 @@ exp: exp CMP exp {
   }
   | STRING_LITERAL {
     $$ = tmpl_expr_new_string ($1, -1);
+    g_free ($1);
   }
   | NAME {
     $$ = tmpl_expr_new_symbol_ref ($1);
+    g_free ($1);
   }
   | NAME '=' exp {
     $$ = tmpl_expr_new_symbol_assign ($1, $3);
+    g_free ($1);
   }
   | exp '.' NAME '(' ')' {
     $$ = tmpl_expr_new_gi_call ($1, $3, NULL);
+    g_free ($3);
   }
   | exp '.' NAME '(' explist ')' {
     $$ = tmpl_expr_new_gi_call ($1, $3, $5);
+    g_free ($3);
   }
   | exp '.' NAME {
     $$ = tmpl_expr_new_getattr ($1, $3);
+    g_free ($3);
   }
   | exp '.' VERSION {
     $$ = tmpl_expr_new_getattr ($1, "version");
   }
   | exp '.' NAME '=' exp {
     $$ = tmpl_expr_new_setattr ($1, $3, $5);
+    g_free ($3);
   }
   | BUILTIN '(' explist ')' {
     $$ = tmpl_expr_new_fn_call ($1, $3);
   }
   | NAME '(' explist ')' {
     $$ = tmpl_expr_new_user_fn_call ($1, $3);
+    g_free ($1);
   }
   | NAME '(' ')' {
     $$ = tmpl_expr_new_user_fn_call ($1, NULL);
+    g_free ($1);
   }
   | '!' exp {
     $$ = tmpl_expr_new_invert_boolean ($2);
   }
   | REQUIRE NAME {
     $$ = tmpl_expr_new_require ($2, NULL);
+    g_free ($2);
   }
   | REQUIRE NAME VERSION STRING_LITERAL {
     $$ = tmpl_expr_new_require ($2, $4);
+    g_free ($2);
+    g_free ($4);
   }
 ;
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]