summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiloslav Trmač <mitr@redhat.com>2014-07-01 18:00:48 (GMT)
committerMiloslav Trmač <mitr@redhat.com>2015-06-18 20:20:53 (GMT)
commitcbad0d5721804a4b7c2d998b00da9e70dc623820 (patch)
treedc1ad18c7d144c1a939495267beec6232033c368
parenta97672540c66c03ed392fc072f0c682281f08989 (diff)
downloadpolkit-cbad0d5721804a4b7c2d998b00da9e70dc623820.tar.gz
polkit-cbad0d5721804a4b7c2d998b00da9e70dc623820.tar.xz
Don't store unrooted jsvals on heap
Don't create a temporary array of jsvals on heap; the GC is not looking for GC roots there. Compare https://developer.mozilla.org/en-US/docs/SpiderMonkey/GC_Rooting_Guide and https://web.archive.org/web/20140305233124/https://developer.mozilla.org/en-US/docs/SpiderMonkey_Garbage_Collection_Tips . https://bugs.freedesktop.org/show_bug.cgi?id=69501
-rw-r--r--src/polkitbackend/polkitbackendjsauthority.c13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/polkitbackend/polkitbackendjsauthority.c b/src/polkitbackend/polkitbackendjsauthority.c
index efb07a9..d02e5e3 100644
--- a/src/polkitbackend/polkitbackendjsauthority.c
+++ b/src/polkitbackend/polkitbackendjsauthority.c
@@ -663,23 +663,22 @@ set_property_strv (PolkitBackendJsAuthority *authority,
{
jsval value_jsval;
JSObject *array_object;
- jsval *jsvals;
guint n;
- jsvals = g_new0 (jsval, value->len);
+ array_object = JS_NewArrayObject (authority->priv->cx, 0, NULL);
+
for (n = 0; n < value->len; n++)
{
JSString *jsstr;
+ jsval val;
+
jsstr = JS_NewStringCopyZ (authority->priv->cx, g_ptr_array_index(value, n));
- jsvals[n] = STRING_TO_JSVAL (jsstr);
+ val = STRING_TO_JSVAL (jsstr);
+ JS_SetElement (authority->priv->cx, array_object, n, &val);
}
- array_object = JS_NewArrayObject (authority->priv->cx, value->len, jsvals);
-
value_jsval = OBJECT_TO_JSVAL (array_object);
JS_SetProperty (authority->priv->cx, obj, name, &value_jsval);
-
- g_free (jsvals);
}