Bug 919051 - Media Recording - memory leak when record a media stream without any tracks. r=roc, r=jsmith
authorRandy Lin <rlin@mozilla.com>
Fri, 27 Sep 2013 17:56:16 +0800
changeset 163826 021e1b5e8cab8dbb644bd377294b447218f522db
parent 163825 b8e4e12a91d9065fe7d8c95d2c4f37cb7725ef18
child 163827 6a5112cc49e760c33b4ae567d51b3135a7961594
push id428
push userbbajaj@mozilla.com
push dateTue, 28 Jan 2014 00:16:25 +0000
treeherdermozilla-release@cd72a7ff3a75 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersroc, jsmith
bugs919051
milestone27.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 919051 - Media Recording - memory leak when record a media stream without any tracks. r=roc, r=jsmith
content/media/MediaRecorder.cpp
content/media/test/Makefile.in
content/media/test/test_mediarecorder_record_nosrc.html
--- a/content/media/MediaRecorder.cpp
+++ b/content/media/MediaRecorder.cpp
@@ -178,16 +178,22 @@ public:
     MOZ_ASSERT(NS_IsMainThread());
 
     SetupStreams();
 
     // Create a thread to read encode media data from MediaEncoder.
     if (!mReadThread) {
       nsresult rv = NS_NewNamedThread("Media Encoder", getter_AddRefs(mReadThread));
       if (NS_FAILED(rv)) {
+        if (mInputPort.get()) {
+          mInputPort->Destroy();
+        }
+        if (mTrackUnionStream.get()) {
+          mTrackUnionStream->Destroy();
+        }
         mRecorder->NotifyError(rv);
         return;
       }
     }
 
     mReadThread->Dispatch(new ExtractRunnable(this), NS_DISPATCH_NORMAL);
   }
 
@@ -358,31 +364,36 @@ MediaRecorder::Start(const Optional<int3
     return;
   }
 
   if (mStream->GetStream()->IsFinished() || mStream->GetStream()->IsDestroyed()) {
     aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
     return;
   }
 
+  if (!mStream->GetPrincipal()) {
+    aResult.Throw(NS_ERROR_DOM_INVALID_STATE_ERR);
+    return;
+  }
+
+  if (!CheckPrincipal()) {
+    aResult.Throw(NS_ERROR_DOM_SECURITY_ERR);
+    return;
+  }
+
   int32_t timeSlice = 0;
   if (aTimeSlice.WasPassed()) {
     if (aTimeSlice.Value() < 0) {
       aResult.Throw(NS_ERROR_INVALID_ARG);
       return;
     }
 
     timeSlice = aTimeSlice.Value();
   }
 
-  if (!CheckPrincipal()) {
-    aResult.Throw(NS_ERROR_DOM_SECURITY_ERR);
-    return;
-  }
-
   mState = RecordingState::Recording;
   // Start a session
   mSession = new Session(this, timeSlice);
   mSession->Start();
 }
 
 void
 MediaRecorder::Stop(ErrorResult& aResult)
--- a/content/media/test/Makefile.in
+++ b/content/media/test/Makefile.in
@@ -116,16 +116,17 @@ MOCHITEST_FILES = \
 		test_volume.html \
 		test_video_to_canvas.html \
 		test_audiowrite.html \
 		test_mediarecorder_creation.html \
 		test_mediarecorder_avoid_recursion.html \
 		test_mediarecorder_record_timeslice.html \
 		test_mediarecorder_record_audiocontext.html \
 		test_mediarecorder_record_stopms.html \
+		test_mediarecorder_record_nosrc.html \
 		test_mozHasAudio.html \
 		test_source_media.html \
 		test_autoplay_contentEditable.html \
 		test_decoder_disable.html \
 		test_mediarecorder_record_no_timeslice.html \
 		test_mediarecorder_reload_crash.html \
 		test_mediarecorder_record_immediate_stop.html \
 		test_mediarecorder_record_session.html \
new file mode 100644
--- /dev/null
+++ b/content/media/test/test_mediarecorder_record_nosrc.html
@@ -0,0 +1,33 @@
+<html>
+<head>
+  <title>Bug 919051 - Media Recording - memory leak when record a media stream without any tracks</title>
+  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script type="text/javascript" src="manifest.js"></script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=919051">Mozill
+a Bug 919051</a>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+function startTest() {
+  var mediastream = document.createElement('video').mozCaptureStream();
+
+  var mr = new MediaRecorder(mediastream);
+  info('create MediaRecorder');
+  try {
+    mr.start();
+    ok(false, 'should get exception');
+  } catch(e) {
+    is(e.name, 'InvalidStateError', "get correct exception");
+  }
+  SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+startTest();
+</script>
+</head>
+</html>
+