From 71a62bb18fe3aebc6668bd37ef6917398ef71ae1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Jonas=20=C3=85dahl?= <jadahl@gmail.com>
Date: Sat, 20 Oct 2018 15:46:37 +0200
Subject: [PATCH 1/2] constraints: Make current placement rule stack allocated

We're not going to keep it past the function scope, so no reason to put
it on the heap. We also didn't free it, so this'll fix a memory leak.

https://gitlab.gnome.org/GNOME/gnome-shell/issues/653
---
 src/core/constraints.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/src/core/constraints.c b/src/core/constraints.c
index a205ea0fd7..3652b3d8e1 100644
--- a/src/core/constraints.c
+++ b/src/core/constraints.c
@@ -787,7 +787,7 @@ constrain_custom_rule (MetaWindow         *window,
   MetaPlacementRule *placement_rule;
   MetaRectangle intersection;
   gboolean constraint_satisfied;
-  MetaPlacementRule *current_rule;
+  MetaPlacementRule current_rule;
   MetaWindow *parent;
   MetaRectangle parent_rect;
 
@@ -820,25 +820,24 @@ constrain_custom_rule (MetaWindow         *window,
   if (check_only)
     return constraint_satisfied;
 
-  current_rule = g_new0 (MetaPlacementRule, 1);
-  *current_rule = *placement_rule;
+  current_rule = *placement_rule;
 
   if (constraint_satisfied)
     goto done;
 
   if (info->current.width != intersection.width &&
-      (current_rule->constraint_adjustment &
+      (current_rule.constraint_adjustment &
        META_PLACEMENT_CONSTRAINT_ADJUSTMENT_FLIP_X))
     {
-      try_flip_window_position (window, info, current_rule,
+      try_flip_window_position (window, info, &current_rule,
                                 META_PLACEMENT_CONSTRAINT_ADJUSTMENT_FLIP_X,
                                 &info->current, &intersection);
     }
   if (info->current.height != intersection.height &&
-      (current_rule->constraint_adjustment &
+      (current_rule.constraint_adjustment &
        META_PLACEMENT_CONSTRAINT_ADJUSTMENT_FLIP_Y))
     {
-      try_flip_window_position (window, info, current_rule,
+      try_flip_window_position (window, info, &current_rule,
                                 META_PLACEMENT_CONSTRAINT_ADJUSTMENT_FLIP_Y,
                                 &info->current, &intersection);
     }
@@ -852,7 +851,7 @@ constrain_custom_rule (MetaWindow         *window,
   if (constraint_satisfied)
     goto done;
 
-  if (current_rule->constraint_adjustment &
+  if (current_rule.constraint_adjustment &
       META_PLACEMENT_CONSTRAINT_ADJUSTMENT_SLIDE_X)
     {
       if (info->current.x != intersection.x)
@@ -860,7 +859,7 @@ constrain_custom_rule (MetaWindow         *window,
       else if (info->current.width != intersection.width)
         info->current.x -= info->current.width - intersection.width;
     }
-  if (current_rule->constraint_adjustment &
+  if (current_rule.constraint_adjustment &
       META_PLACEMENT_CONSTRAINT_ADJUSTMENT_SLIDE_Y)
     {
       if (info->current.y != intersection.y)
@@ -878,13 +877,13 @@ constrain_custom_rule (MetaWindow         *window,
   if (constraint_satisfied)
     goto done;
 
-  if (current_rule->constraint_adjustment &
+  if (current_rule.constraint_adjustment &
       META_PLACEMENT_CONSTRAINT_ADJUSTMENT_RESIZE_X)
     {
       info->current.x = intersection.x;
       info->current.width = intersection.width;
     }
-  if (current_rule->constraint_adjustment &
+  if (current_rule.constraint_adjustment &
       META_PLACEMENT_CONSTRAINT_ADJUSTMENT_RESIZE_Y)
     {
       info->current.y = intersection.y;
-- 
2.19.1

