Bug 804741 - close our recorder output file handle because recorder dup()s it. r=mwu
authorMike Habicher <mikeh@mozilla.com>
Mon, 29 Oct 2012 16:16:42 -0700
changeset 111846 f7e3e8c6e632ff175a17689ddaf8a3a0bd028954
parent 111845 4051d30c8f35ee5aa5579531d8f243e1586d9201
child 111847 a235cb7f4de1fda9d5606d92355948e8e0f80a11
push id93
push usernmatsakis@mozilla.com
push dateWed, 31 Oct 2012 21:26:57 +0000
reviewersmwu
bugs804741
milestone19.0a1
Bug 804741 - close our recorder output file handle because recorder dup()s it. r=mwu
dom/camera/GonkCameraControl.cpp
--- a/dom/camera/GonkCameraControl.cpp
+++ b/dom/camera/GonkCameraControl.cpp
@@ -23,16 +23,17 @@
 #include "libcameraservice/CameraHardwareInterface.h"
 #include "camera/CameraParameters.h"
 #include "nsCOMPtr.h"
 #include "nsDOMClassInfo.h"
 #include "nsMemory.h"
 #include "jsapi.h"
 #include "nsThread.h"
 #include <media/MediaProfiles.h>
+#include "mozilla/FileUtils.h"
 #include "nsDirectoryServiceDefs.h" // for NS_GetSpecialDirectory
 #include "nsPrintfCString.h"
 #include "DOMCameraManager.h"
 #include "GonkCameraHwMgr.h"
 #include "DOMCameraCapabilities.h"
 #include "DOMCameraControl.h"
 #include "GonkRecorderProfiles.h"
 #include "GonkCameraControl.h"
@@ -729,30 +730,27 @@ nsGonkCameraControl::StartRecordingImpl(
    */
   nsCOMPtr<nsIFile> filename = aStartRecording->mFolder;
   filename->AppendRelativePath(aStartRecording->mFilename);
 
   nsAutoCString nativeFilename;
   filename->GetNativePath(nativeFilename);
   DOM_CAMERA_LOGI("Video filename is '%s'\n", nativeFilename.get());
 
-  int fd = open(nativeFilename.get(), O_RDWR | O_CREAT, 0644);
+  ScopedClose fd(open(nativeFilename.get(), O_RDWR | O_CREAT, 0644));
   if (fd < 0) {
     DOM_CAMERA_LOGE("Couldn't create file '%s': (%d) %s\n", nativeFilename.get(), errno, strerror(errno));
     return NS_ERROR_FAILURE;
   }
 
-  if (SetupRecording(fd) != NS_OK) {
-    DOM_CAMERA_LOGE("SetupRecording() failed\n");
-    close(fd);
-    return NS_ERROR_FAILURE;
-  }
+  nsresult rv = SetupRecording(fd);
+  NS_ENSURE_SUCCESS(rv, rv);
+
   if (mRecorder->start() != OK) {
     DOM_CAMERA_LOGE("mRecorder->start() failed\n");
-    close(fd);
     return NS_ERROR_FAILURE;
   }
 
   return NS_OK;
 }
 
 nsresult
 nsGonkCameraControl::StopRecordingImpl(StopRecordingTask* aStopRecording)