Bug 1139721 - Fix camera memory leaks for onfacedetected events, failed initializations and capabilities. r=mikeh

This commit is contained in:
Andrew Osmond 2015-04-17 07:09:54 -04:00
parent d63ce914f4
commit 1f0078bbd5
2 changed files with 8 additions and 4 deletions

View File

@ -323,6 +323,7 @@ CameraCapabilities::CameraCapabilities(nsPIDOMWindow* aWindow,
, mCameraControl(aCameraControl)
{
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
MOZ_COUNT_CTOR(CameraCapabilities);
if (mCameraControl) {
mListener = new CameraClosedListenerProxy<CameraCapabilities>(this);
mCameraControl->AddListener(mListener);

View File

@ -306,7 +306,7 @@ nsDOMCameraControl::nsDOMCameraControl(uint32_t aCameraId,
nsDOMCameraControl::~nsDOMCameraControl()
{
DOM_CAMERA_LOGT("%s:%d : this=%p\n", __func__, __LINE__, this);
/*invoke DOMMdediastream destroy*/
/*invoke DOMMediaStream destroy*/
Destroy();
}
@ -1373,10 +1373,9 @@ nsDOMCameraControl::OnFacesDetected(const nsTArray<ICameraControl::Face>& aFaces
uint32_t len = aFaces.Length();
if (faces.SetCapacity(len)) {
nsRefPtr<DOMCameraDetectedFace> f;
for (uint32_t i = 0; i < len; ++i) {
f = new DOMCameraDetectedFace(static_cast<DOMMediaStream*>(this), aFaces[i]);
*faces.AppendElement() = f.forget().take();
*faces.AppendElement() =
new DOMCameraDetectedFace(static_cast<DOMMediaStream*>(this), aFaces[i]);
}
}
@ -1427,6 +1426,10 @@ nsDOMCameraControl::OnUserError(CameraControlListener::UserContext aContext, nsr
switch (aContext) {
case CameraControlListener::kInStartCamera:
promise = mGetCameraPromise.forget();
// If we failed to open the camera, we never actually provided a reference
// for the application to release explicitly. Thus we must clear our handle
// here to ensure everything is freed.
mCameraControl = nullptr;
break;
case CameraControlListener::kInStopCamera: