]> git.draconx.ca Git - upkg.git/commitdiff
Ensure object property references are released.
authorNick Bowler <nbowler@draconx.ca>
Thu, 30 Jan 2020 19:27:56 +0000 (14:27 -0500)
committerNick Bowler <nbowler@draconx.ca>
Fri, 31 Jan 2020 14:32:54 +0000 (09:32 -0500)
It seems that g_object_set_property adds to the reference count of
object properties, so we must release our original reference when
deserializing.

Add finalizers for Engine.Texture and Engine.Palette to release
the palette memory.

src/engine/palette.gob
src/engine/texture.gob
src/uobject/uobject.c

index 08d0b786bbec2ce10f8c4a749c53c4706b80880d..ce5745926c773847dc0d9793dea451bd3233855f 100644 (file)
@@ -1,7 +1,7 @@
 %alltop{
 /*
  *  upkg: tool for manipulating Unreal Tournament packages.
- *  Copyright © 2011 Nick Bowler
+ *  Copyright © 2011, 2020 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -33,7 +33,7 @@ typedef unsigned char engine_palette_rgba[4];
 class Engine:Palette from U:Object (dynamic)
 {
        public unsigned entries = 0;
-       public engine_palette_rgba *rgba = NULL;
+       public engine_palette_rgba *rgba = NULL destroywith free;
 
        override (U:Object) int deserialize(U:Object *uo)
        {
index 49af5381a37b43c19d9babf16ce11e5ccea77be6..981c89891ab25b499e354a58b4391086e4de828b 100644 (file)
@@ -1,7 +1,7 @@
 %alltop{
 /*
  *  upkg: tool for manipulating Unreal Tournament packages.
- *  Copyright © 2009-2011 Nick Bowler
+ *  Copyright © 2009-2012, 2020 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -119,8 +119,8 @@ class Engine:Texture from U:Object (dynamic)
 
        private float DrawScale;
 
-       private Engine:Palette *Palette;
-       private Engine:Texture *DetailTexture;
+       private Engine:Palette *Palette = NULL destroywith g_object_unref;
+       private Engine:Texture *DetailTexture = NULL destroywith g_object_unref;
 
        private struct engine_texture_data **mipmap_data;
        private unsigned char mipmap_count;
index c3cc24662ce4a69980b0086c8693c4b651f05d0a..867390f2d7c07ced6bba9de4a3f20c0464d2b869 100644 (file)
@@ -1,6 +1,6 @@
 /*
  *  upkg: tool for manipulating Unreal Tournament packages.
- *  Copyright © 2009-2012, 2015 Nick Bowler
+ *  Copyright © 2009-2012, 2015, 2020 Nick Bowler
  *
  *  This program is free software: you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -376,6 +376,12 @@ static unsigned long deserialize_property(UObject *uo, struct prop_head *head)
                if (rc != 0)
                        return 0;
                g_object_set_property(G_OBJECT(uo), head->prop_name, &val);
+
+               /*
+                * g_object_set_property increments refcount,
+                * release our reference.
+                */
+               g_object_unref(g_value_get_object(&val));
                break;
        case PROPERTY_FLOAT:
                if (head->size != 4 || priv->nbuf-len < head->size)