[gtk/matthiasc/for-master: 18/18] css: Plug a memory leak



commit 75db19c78948ddfc768a043aa9a8f6a442433d2d
Author: Matthias Clasen <mclasen redhat com>
Date:   Thu Jul 9 12:14:18 2020 -0400

    css: Plug a memory leak
    
    When a rule has no styles, we don't add it
    to our ruleset. Since we are not adopting
    the selectors in this case, we must free them.
    
    Fixes: #2921

 gtk/gtkcssprovider.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkcssprovider.c b/gtk/gtkcssprovider.c
index 51b545f29d..7dbc6924f5 100644
--- a/gtk/gtkcssprovider.c
+++ b/gtk/gtkcssprovider.c
@@ -562,10 +562,12 @@ css_provider_commit (GtkCssProvider  *css_provider,
 
   if (ruleset->styles == NULL)
     {
+      for (i = 0; i < n_selectors; i++)
+        _gtk_css_selector_free (selectors[i]);
       return;
     }
 
-  for (i = 0; i < n_selectors; i ++)
+  for (i = 0; i < n_selectors; i++)
     {
       GtkCssRuleset *new;
 
@@ -915,7 +917,7 @@ parse_ruleset (GtkCssScanner *scanner)
     {
       guint i;
       gtk_css_parser_error_syntax (scanner->parser, "Expected '{' after selectors");
-      for (i = 0; i < n_selectors; i ++)
+      for (i = 0; i < n_selectors; i++)
         _gtk_css_selector_free (selectors[i]);
       gtk_css_parser_skip_until (scanner->parser, GTK_CSS_TOKEN_OPEN_CURLY);
       gtk_css_parser_skip (scanner->parser);


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