[gjs/wip/ptomato/mozjs45prep: 1/16] object: Fix memory leak in resolve



commit 9050118c9e77849a29d0193aea8f710038bfd5fa
Author: Philip Chimento <philip endlessm com>
Date:   Thu Mar 16 15:43:09 2017 -0700

    object: Fix memory leak in resolve
    
    The "name" string, allocated in gjs_get_string_id(), wasn't getting freed
    at every exit point of the function. (It will be nice to clean this up in
    1.49.x with our autoptr classes...)
    
    After a certain point in the function it's not needed, so we just free
    the string there.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=780171

 gi/object.cpp |   15 +++++++++++----
 1 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/gi/object.cpp b/gi/object.cpp
index c68ad4c..63731df 100644
--- a/gi/object.cpp
+++ b/gi/object.cpp
@@ -607,7 +607,7 @@ is_vfunc_unchanged(GIVFuncInfo *info,
 
 static GIVFuncInfo *
 find_vfunc_on_parents(GIObjectInfo *info,
-                      gchar        *name,
+                      const char   *name,
                       bool         *out_defined_by_parent)
 {
     GIVFuncInfo *vfunc = NULL;
@@ -774,12 +774,14 @@ object_instance_resolve(JSContext       *context,
          * rest.
          */
 
-        gchar *name_without_vfunc_ = &name[6];
+        const char *name_without_vfunc_ = &name[6];  /* lifetime tied to name */
         GIVFuncInfo *vfunc;
         bool defined_by_parent;
 
         vfunc = find_vfunc_on_parents(priv->info, name_without_vfunc_, &defined_by_parent);
         if (vfunc != NULL) {
+            g_free(name);
+
             /* In the event that the vfunc is unchanged, let regular
              * prototypal inheritance take over. */
             if (defined_by_parent && is_vfunc_unchanged(vfunc, priv->gtype)) {
@@ -818,8 +820,13 @@ object_instance_resolve(JSContext       *context,
      * this could be done better.  See
      * https://bugzilla.gnome.org/show_bug.cgi?id=632922
      */
-    if (method_info == NULL)
-        return object_instance_resolve_no_info(context, obj, resolved, priv, name);
+    if (method_info == NULL) {
+        bool retval = object_instance_resolve_no_info(context, obj, resolved, priv, name);
+        g_free(name);
+        return retval;
+    }
+
+    g_free(name);
 
 #if GJS_VERBOSE_ENABLE_GI_USAGE
     _gjs_log_info_usage((GIBaseInfo*) method_info);


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