[gnome-boxes] box-config: Don't access passed array after method returns



commit 498461a841545a20488f3a08bca4b79cd2185a83
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Mar 16 15:37:14 2016 +0000

    box-config: Don't access passed array after method returns
    
    Seems we can't rely on the passed array of structs to be around in a
    closure and get a crash.
    
    This patch fixes a crash when going back to overview from a VNC display.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=761202

 src/box-config.vala |   21 ++++++++++++---------
 1 files changed, 12 insertions(+), 9 deletions(-)
---
diff --git a/src/box-config.vala b/src/box-config.vala
index ff4e01a..15843b5 100644
--- a/src/box-config.vala
+++ b/src/box-config.vala
@@ -119,10 +119,11 @@ public class Boxes.BoxConfig: GLib.Object, Boxes.IConfig {
         save ();
     }
 
-    private void load_property (Object object, string property_name, Value default_value) {
+    private ParamSpec? load_property (Object object, string property_name, Value default_value) {
         var property = object.get_class ().find_property (property_name);
         if (property == null) {
             debug ("You forgot the property '%s' needs to have public getter!", property_name);
+            return null;
         }
 
         var value = Value (property.value_type);
@@ -141,19 +142,21 @@ public class Boxes.BoxConfig: GLib.Object, Boxes.IConfig {
         }
 
         object.set_property (property_name, value);
+
+        return property;
     }
 
     public void save_properties (Object object, SavedProperty[] properties) {
-        foreach (var prop in properties)
-            load_property (object, prop.name, prop.default_value);
+        foreach (var prop in properties) {
+            var property = load_property (object, prop.name, prop.default_value);
+            if (property == null)
+                return;
 
-        object.notify.connect ((object, pspec) => {
-            foreach (var prop in properties)
-                if (pspec.name == prop.name) {
+            object.notify.connect ((object, pspec) => {
+                if (pspec.name == property.name)
                     save_property (object, pspec.name);
-                    break;
-                }
-        });
+           });
+        }
     }
 
     private string? filter_data;


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