Bug 1019843 - avoid a leak when init() fails. r=jorendorff
authorGuillaume Turri <guillaume.turri@gmail.com>
Sat, 05 Jul 2014 00:37:00 +0200
changeset 213834 1ff371321520ed2886c83a246878af17b4f4a6d0
parent 213833 545d28bfe4fbfeb87576cfb2e4e1322ccaba8ac5
child 213835 1a49305c62362b11e530821274cc9dd05272a408
push id3857
push userraliiev@mozilla.com
push dateTue, 02 Sep 2014 16:39:23 +0000
treeherdermozilla-beta@5638b907b505 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorendorff
bugs1019843
milestone33.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1019843 - avoid a leak when init() fails. r=jorendorff
js/src/builtin/MapObject.cpp
--- a/js/src/builtin/MapObject.cpp
+++ b/js/src/builtin/MapObject.cpp
@@ -1165,19 +1165,18 @@ MapObject::finalize(FreeOp *fop, JSObjec
 bool
 MapObject::construct(JSContext *cx, unsigned argc, Value *vp)
 {
     Rooted<JSObject*> obj(cx, NewBuiltinClassInstance(cx, &class_));
     if (!obj)
         return false;
 
     ValueMap *map = cx->new_<ValueMap>(cx->runtime());
-    if (!map)
-        return false;
-    if (!map->init()) {
+    if (!map || !map->init()) {
+        js_delete(map);
         js_ReportOutOfMemory(cx);
         return false;
     }
     obj->setPrivate(map);
 
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.hasDefined(0)) {
         ForOfIterator iter(cx);
@@ -1675,19 +1674,18 @@ SetObject::finalize(FreeOp *fop, JSObjec
 bool
 SetObject::construct(JSContext *cx, unsigned argc, Value *vp)
 {
     Rooted<JSObject*> obj(cx, NewBuiltinClassInstance(cx, &class_));
     if (!obj)
         return false;
 
     ValueSet *set = cx->new_<ValueSet>(cx->runtime());
-    if (!set)
-        return false;
-    if (!set->init()) {
+    if (!set || !set->init()) {
+        js_delete(set);
         js_ReportOutOfMemory(cx);
         return false;
     }
     obj->setPrivate(set);
 
     CallArgs args = CallArgsFromVp(argc, vp);
     if (args.hasDefined(0)) {
         RootedValue keyVal(cx);