[xpcom] Fix lifetime issue with dict keys, the converted data was freed too early
[browser-dbus-bridge.git] / xpcom-dbusservice / DBusMarshaling.cpp
index 38e2122246358312013918c26078427dee71e6e8..0512263dafb350f67646b2d684cc74dcce6d9418 100644 (file)
@@ -482,7 +482,6 @@ addVariantToIter(JSContext* cx, nsIVariant *aVariant, DBusMessageIter *aIter, DB
                         for (int p = 0; p < props->length; p++)
                         {
                             jsval propname;
-                            nsCAutoString tmpsig;
                             JS_IdToValue(cx, props->vector[p], &propname);
 
                             // Start the dict container
@@ -491,8 +490,9 @@ addVariantToIter(JSContext* cx, nsIVariant *aVariant, DBusMessageIter *aIter, DB
                                                              NULL, &dictIter);
 
                             JSString *prop_string = JS_ValueToString(cx, propname);
-                            const char *cstr = NS_ConvertUTF16toUTF8(JS_GetStringChars(prop_string),
-                                                               JS_GetStringLength(prop_string)).get();
+                            nsCAutoString u8str = NS_ConvertUTF16toUTF8(JS_GetStringChars(prop_string),
+                                                                        JS_GetStringLength(prop_string));
+                            const char *cstr = u8str.get();
                             // TODO: we only use strings as keys currently, although
                             // the spec allows any basic type to be a key and we
                             // probably *could* use the property index.