Title: [148566] trunk/Source/WebCore
Revision
148566
Author
[email protected]
Date
2013-04-16 16:17:54 -0700 (Tue, 16 Apr 2013)

Log Message

Repeated use of decodeAudioData() causes leak
https://bugs.webkit.org/show_bug.cgi?id=114709

Reviewed by Geoffrey Garen.

Report the correct size of the AudioBuffer to the garbage collector so that creating
these large buffers will trigger garbage collection.

* Modules/webaudio/AudioBuffer.cpp:
(WebCore::AudioBuffer::memoryCost): Added; simple sum of the buffer sizes in m_channels;
* Modules/webaudio/AudioBuffer.h:
* Modules/webaudio/AudioBuffer.idl: Add the CustomToJSObject flag.
* WebCore.xcodeproj/project.pbxproj:
* bindings/js/JSAudioBufferCustom.cpp: Added.
(WebCore::toJS): Added; report the extra size of an AudioBuffer when the wrapper
    is created.

Modified Paths

Added Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (148565 => 148566)


--- trunk/Source/WebCore/ChangeLog	2013-04-16 23:01:38 UTC (rev 148565)
+++ trunk/Source/WebCore/ChangeLog	2013-04-16 23:17:54 UTC (rev 148566)
@@ -1,3 +1,22 @@
+2013-04-16  Jer Noble  <[email protected]>
+
+        Repeated use of decodeAudioData() causes leak
+        https://bugs.webkit.org/show_bug.cgi?id=114709
+
+        Reviewed by Geoffrey Garen.
+
+        Report the correct size of the AudioBuffer to the garbage collector so that creating
+        these large buffers will trigger garbage collection.
+
+        * Modules/webaudio/AudioBuffer.cpp:
+        (WebCore::AudioBuffer::memoryCost): Added; simple sum of the buffer sizes in m_channels;
+        * Modules/webaudio/AudioBuffer.h:
+        * Modules/webaudio/AudioBuffer.idl: Add the CustomToJSObject flag.
+        * WebCore.xcodeproj/project.pbxproj:
+        * bindings/js/JSAudioBufferCustom.cpp: Added.
+        (WebCore::toJS): Added; report the extra size of an AudioBuffer when the wrapper
+            is created.
+
 2013-04-16  Beth Dakin  <[email protected]>
 
         Need a new layout milestone to notify bundle clients when the header has been 

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp (148565 => 148566)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp	2013-04-16 23:01:38 UTC (rev 148565)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.cpp	2013-04-16 23:17:54 UTC (rev 148566)
@@ -116,6 +116,14 @@
     }
 }
 
+size_t AudioBuffer::memoryCost() const
+{
+    size_t cost = 0;
+    for (unsigned i = 0; i < m_channels.size() ; ++i)
+        cost += m_channels[i]->byteLength();
+    return cost;
+}
+
 } // namespace WebCore
 
 #endif // ENABLE(WEB_AUDIO)

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h (148565 => 148566)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h	2013-04-16 23:01:38 UTC (rev 148565)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.h	2013-04-16 23:17:54 UTC (rev 148566)
@@ -67,6 +67,8 @@
     // releaseMemory() can be called when the AudioContext goes away, so we can release the memory earlier than when the garbage collection happens.
     // Careful! Only call this when the page unloads, after the AudioContext is no longer processing.
     void releaseMemory();
+
+    size_t memoryCost() const;
     
 protected:
     AudioBuffer(unsigned numberOfChannels, size_t numberOfFrames, float sampleRate);

Modified: trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl (148565 => 148566)


--- trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl	2013-04-16 23:01:38 UTC (rev 148565)
+++ trunk/Source/WebCore/Modules/webaudio/AudioBuffer.idl	2013-04-16 23:17:54 UTC (rev 148566)
@@ -28,6 +28,7 @@
 
 [
     Conditional=WEB_AUDIO,
+    CustomToJSObject,
     ImplementationLacksVTable
 ] interface AudioBuffer {
     readonly attribute long length; // in sample-frames

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (148565 => 148566)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-04-16 23:01:38 UTC (rev 148565)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2013-04-16 23:17:54 UTC (rev 148566)
@@ -5236,6 +5236,7 @@
 		CDC69DDA16371FD4007C38DF /* WebCoreFullScreenPlaceholderView.h in Headers */ = {isa = PBXBuildFile; fileRef = CDC69DD816371FD3007C38DF /* WebCoreFullScreenPlaceholderView.h */; settings = {ATTRIBUTES = (Private, ); }; };
 		CDC69DDB16371FD4007C38DF /* WebCoreFullScreenPlaceholderView.mm in Sources */ = {isa = PBXBuildFile; fileRef = CDC69DD916371FD3007C38DF /* WebCoreFullScreenPlaceholderView.mm */; };
 		CDD525D7145B6DD0008D204D /* JSHTMLMediaElementCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDF65CCC145B6AFE00C4C7AA /* JSHTMLMediaElementCustom.cpp */; };
+		CDDE691F171DFAD000A44D89 /* JSAudioBufferCustom.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDDE691D171DF89100A44D89 /* JSAudioBufferCustom.cpp */; };
 		CDEA763014608A53008B31F1 /* PlatformClockCA.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA762E146084DE008B31F1 /* PlatformClockCA.cpp */; };
 		CDEA76341460B56F008B31F1 /* ClockGeneric.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA76321460AE29008B31F1 /* ClockGeneric.cpp */; };
 		CDEA76351460B71A008B31F1 /* Clock.cpp in Sources */ = {isa = PBXBuildFile; fileRef = CDEA76331460B462008B31F1 /* Clock.cpp */; };
@@ -11996,6 +11997,7 @@
 		CDC69DD916371FD3007C38DF /* WebCoreFullScreenPlaceholderView.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreFullScreenPlaceholderView.mm; sourceTree = "<group>"; };
 		CDCE5CD014633BC900D47CCA /* EventTargetFactory.in */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = EventTargetFactory.in; sourceTree = "<group>"; };
 		CDD1E525167BA56400CE820B /* TextTrackRepresentation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextTrackRepresentation.h; sourceTree = "<group>"; };
+		CDDE691D171DF89100A44D89 /* JSAudioBufferCustom.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; path = JSAudioBufferCustom.cpp; sourceTree = "<group>"; };
 		CDEA762C14608224008B31F1 /* Clock.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Clock.h; sourceTree = "<group>"; };
 		CDEA762E146084DE008B31F1 /* PlatformClockCA.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = PlatformClockCA.cpp; sourceTree = "<group>"; };
 		CDEA762F146084EE008B31F1 /* PlatformClockCA.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PlatformClockCA.h; sourceTree = "<group>"; };
@@ -18804,6 +18806,7 @@
 				86243D0011BC31F700CC006A /* JSArrayBufferViewHelper.h */,
 				BC2ED6BB0C6BD2F000920BFF /* JSAttrCustom.cpp */,
 				FDEAAAEF12B02EE400DCF33B /* JSAudioBufferSourceNodeCustom.cpp */,
+				CDDE691D171DF89100A44D89 /* JSAudioBufferCustom.cpp */,
 				FDEAAAF012B02EE400DCF33B /* JSAudioContextCustom.cpp */,
 				FD8AA63B1695148E00D2EA68 /* JSBiquadFilterNodeCustom.cpp */,
 				8931DE5A14C44C44000DC9D2 /* JSBlobCustom.cpp */,
@@ -25465,6 +25468,7 @@
 				BCBFB53C0DCD29CF0019B3E5 /* JSDOMWindowShell.cpp in Sources */,
 				A80A9423149F225E00989291 /* JSDOMWindowWebAudioCustom.cpp in Sources */,
 				A80A9425149F227100989291 /* JSDOMWindowWebSocketCustom.cpp in Sources */,
+				CDDE691F171DFAD000A44D89 /* JSAudioBufferCustom.cpp in Sources */,
 				FD7868B9136B999200D403DF /* JSDynamicsCompressorNode.cpp in Sources */,
 				65DF31F909D1CC60000BE325 /* JSElement.cpp in Sources */,
 				BC2ED5550C6B9BD300920BFF /* JSElementCustom.cpp in Sources */,

Added: trunk/Source/WebCore/bindings/js/JSAudioBufferCustom.cpp (0 => 148566)


--- trunk/Source/WebCore/bindings/js/JSAudioBufferCustom.cpp	                        (rev 0)
+++ trunk/Source/WebCore/bindings/js/JSAudioBufferCustom.cpp	2013-04-16 23:17:54 UTC (rev 148566)
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2013 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "JSAudioBuffer.h"
+
+#include "AudioBuffer.h"
+
+using namespace JSC;
+
+namespace WebCore {
+
+JSValue toJS(ExecState* exec, JSDOMGlobalObject* globalObject, AudioBuffer* audioBuffer)
+{
+    if (!audioBuffer)
+        return jsNull();
+
+    JSDOMWrapper* wrapper = getCachedWrapper(currentWorld(exec), audioBuffer);
+    if (wrapper)
+        return wrapper;
+
+    wrapper = CREATE_DOM_WRAPPER(exec, globalObject, AudioBuffer, audioBuffer);
+
+    exec->heap()->reportExtraMemoryCost(audioBuffer->memoryCost());
+
+    return wrapper;
+}
+
+}
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to