Bug 1246157 - avoid memory leak when bindings->init fails. r=jcoppeard
authorBogdan Postelnicu <bogdan.postelnicu>
Mon, 08 Feb 2016 00:53:00 +0100
changeset 283591 5253aba43949e15fbd74d12fa47a44c8a72a5193
parent 283590 7b7110c017c5b9ca956ba24fc7eee6aa3c96d591
child 283592 2786cb0f81d74d9cf949d98a7c9f2f41604b679c
push id71600
push usercbook@mozilla.com
push dateTue, 09 Feb 2016 14:39:47 +0000
treeherdermozilla-inbound@2786cb0f81d7 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjcoppeard
bugs1246157
milestone47.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 1246157 - avoid memory leak when bindings->init fails. r=jcoppeard
js/src/builtin/ModuleObject.cpp
--- a/js/src/builtin/ModuleObject.cpp
+++ b/js/src/builtin/ModuleObject.cpp
@@ -586,16 +586,17 @@ ModuleObject::create(ExclusiveContext* c
     if (!scope)
         return nullptr;
     self->initReservedSlot(StaticScopeSlot, ObjectOrNullValue(scope));
 
     Zone* zone = cx->zone();
     IndirectBindingMap* bindings = zone->new_<IndirectBindingMap>(zone);
     if (!bindings || !bindings->init()) {
         ReportOutOfMemory(cx);
+        js_delete<IndirectBindingMap>(bindings);
         return nullptr;
     }
 
     self->initReservedSlot(ImportBindingsSlot, PrivateValue(bindings));
 
     FunctionDeclarationVector* funDecls = zone->new_<FunctionDeclarationVector>(zone);
     if (!funDecls) {
         ReportOutOfMemory(cx);
@@ -837,16 +838,17 @@ ModuleObject::createNamespace(JSContext*
     RootedModuleNamespaceObject ns(cx, ModuleNamespaceObject::create(cx, self));
     if (!ns)
         return nullptr;
 
     Zone* zone = cx->zone();
     IndirectBindingMap* bindings = zone->new_<IndirectBindingMap>(zone);
     if (!bindings || !bindings->init()) {
         ReportOutOfMemory(cx);
+        js_delete<IndirectBindingMap>(bindings);
         return nullptr;
     }
 
     self->initReservedSlot(NamespaceSlot, ObjectValue(*ns));
     self->initReservedSlot(NamespaceExportsSlot, ObjectValue(*exports));
     self->initReservedSlot(NamespaceBindingsSlot, PrivateValue(bindings));
     return ns;
 }