[jscorebus] Fix memory leaks in D-Bus message signature handling
authorKalle Vahlman <kalle.vahlman@movial.com>
Wed, 15 Apr 2009 09:41:21 +0000 (12:41 +0300)
committerKalle Vahlman <kalle.vahlman@movial.com>
Wed, 15 Apr 2009 09:41:21 +0000 (12:41 +0300)
jscorebus/jscorebus-marshal.c

index 10cf3f4478bbfbcf81fd3328be051f1a92b5e976..e791ab3df203ff392d880a09bee675274bbefe49 100644 (file)
@@ -83,14 +83,16 @@ gboolean jsvalue_array_append_to_message_iter (JSContextRef context,
   dbus_signature_iter_init(&siter, sig);
   i = 0;
   do {
-    const char *arg_sig = dbus_signature_iter_get_signature(&siter);
+    char *arg_sig = dbus_signature_iter_get_signature(&siter);
     if (!jsvalue_append_to_message_iter(context, jsvalues[i++], iter, arg_sig))
     {
       g_warning("Appending '%s' to message failed!", arg_sig);
+      dbus_free(arg_sig);
       if (sig != signature)
         g_free(sig);
       return FALSE;
     }
+    dbus_free(arg_sig);
   } while (dbus_signature_iter_next(&siter));
   
   if (sig != signature)
@@ -174,9 +176,11 @@ gboolean jsvalue_append_to_message_iter(JSContextRef context,
           if (!dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
                                                 dict_signature, &subiter))
           {
+            dbus_free(dict_signature);
             g_warning("Memory exhausted!");
             return FALSE;
           }
+          dbus_free(dict_signature);
           propnames = JSObjectCopyPropertyNames(context, (JSObjectRef)jsvalue);
           props = JSPropertyNameArrayGetCount(propnames);
 
@@ -202,9 +206,11 @@ gboolean jsvalue_append_to_message_iter(JSContextRef context,
             cstr = string_from_jsstring(context, jsstr);
             dbus_message_iter_append_basic(&dictiter, DBUS_TYPE_STRING, &cstr);
             g_free(cstr);
+            cstr = dbus_signature_iter_get_signature(&dictsubsiter);
             jsvalue_append_to_message_iter(context,
               JSObjectGetProperty(context, (JSObjectRef)jsvalue, jsstr, NULL),
-              &dictiter, dbus_signature_iter_get_signature(&dictsubsiter));
+              &dictiter, cstr);
+            dbus_free(cstr);
             dbus_message_iter_close_container(&subiter, &dictiter);
           }
           dbus_message_iter_close_container(iter, &subiter);