Bug 1129051 - Fix double free in Camera Control Listener. Fix webrtc memory leak. r=aosmond

This commit is contained in:
Roger Yang 2015-04-28 16:08:40 -04:00
parent 018e6f3019
commit f0087f9693
8 changed files with 14 additions and 16 deletions

View File

@ -166,7 +166,7 @@ CameraControlImpl::OnFacesDetected(const nsTArray<Face>& aFaces)
}
void
CameraControlImpl::OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType)
CameraControlImpl::OnTakePictureComplete(const uint8_t* aData, uint32_t aLength, const nsAString& aMimeType)
{
// This callback can run on threads other than the Main Thread and
// the Camera Thread. On Gonk, it is called from the camera

View File

@ -57,7 +57,7 @@ protected:
// Event handlers.
void OnAutoFocusComplete(bool aAutoFocusSucceeded);
void OnFacesDetected(const nsTArray<Face>& aFaces);
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType);
void OnTakePictureComplete(const uint8_t* aData, uint32_t aLength, const nsAString& aMimeType);
void OnRateLimitPreview(bool aLimit);
bool OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight);

View File

@ -89,7 +89,7 @@ public:
virtual void OnAutoFocusComplete(bool aAutoFocusSucceeded) { }
virtual void OnAutoFocusMoving(bool aIsMoving) { }
virtual void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType) { }
virtual void OnTakePictureComplete(const uint8_t* aData, uint32_t aLength, const nsAString& aMimeType) { }
virtual void OnFacesDetected(const nsTArray<ICameraControl::Face>& aFaces) { }
enum UserContext

View File

@ -341,18 +341,20 @@ DOMCameraControlListener::OnAutoFocusComplete(bool aAutoFocusSucceeded)
}
void
DOMCameraControlListener::OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType)
DOMCameraControlListener::OnTakePictureComplete(const uint8_t* aData, uint32_t aLength, const nsAString& aMimeType)
{
class Callback : public DOMCallback
{
public:
Callback(nsMainThreadPtrHandle<nsISupports> aDOMCameraControl,
uint8_t* aData, uint32_t aLength, const nsAString& aMimeType)
const uint8_t* aData, uint32_t aLength, const nsAString& aMimeType)
: DOMCallback(aDOMCameraControl)
, mData(aData)
, mLength(aLength)
, mMimeType(aMimeType)
{ }
{
mData = (uint8_t*) malloc(aLength);
memcpy(mData, aData, aLength);
}
void
RunCallback(nsDOMCameraControl* aDOMCameraControl) override

View File

@ -21,7 +21,7 @@ public:
virtual void OnAutoFocusComplete(bool aAutoFocusSucceeded) override;
virtual void OnAutoFocusMoving(bool aIsMoving) override;
virtual void OnFacesDetected(const nsTArray<ICameraControl::Face>& aFaces) override;
virtual void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType) override;
virtual void OnTakePictureComplete(const uint8_t* aData, uint32_t aLength, const nsAString& aMimeType) override;
virtual void OnHardwareStateChange(HardwareState aState, nsresult aReason) override;
virtual void OnPreviewStateChange(PreviewState aState) override;

View File

@ -1534,14 +1534,10 @@ nsGonkCameraControl::OnTakePictureComplete(uint8_t* aData, uint32_t aLength)
{
ReentrantMonitorAutoEnter mon(mReentrantMonitor);
uint8_t* data = new uint8_t[aLength];
memcpy(data, aData, aLength);
nsString s(NS_LITERAL_STRING("image/"));
s.Append(mFileFormat);
DOM_CAMERA_LOGI("Got picture, type '%s', %u bytes\n", NS_ConvertUTF16toUTF8(s).get(), aLength);
OnTakePictureComplete(data, aLength, s);
OnTakePictureComplete(aData, aLength, s);
if (mResumePreviewAfterTakingPicture) {
nsresult rv = StartPreview();

View File

@ -590,7 +590,7 @@ MediaEngineGonkVideoSource::OnUserError(UserContext aContext, nsresult aError)
}
void
MediaEngineGonkVideoSource::OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType)
MediaEngineGonkVideoSource::OnTakePictureComplete(const uint8_t* aData, uint32_t aLength, const nsAString& aMimeType)
{
// It needs to start preview because Gonk camera will stop preview while
// taking picture.
@ -601,7 +601,7 @@ MediaEngineGonkVideoSource::OnTakePictureComplete(uint8_t* aData, uint32_t aLeng
class GenerateBlobRunnable : public nsRunnable {
public:
GenerateBlobRunnable(nsTArray<nsRefPtr<PhotoCallback>>& aCallbacks,
uint8_t* aData,
const uint8_t* aData,
uint32_t aLength,
const nsAString& aMimeType)
: mPhotoDataLength(aLength)

View File

@ -74,7 +74,7 @@ public:
void GetRotation();
bool OnNewPreviewFrame(layers::Image* aImage, uint32_t aWidth, uint32_t aHeight) override;
void OnUserError(UserContext aContext, nsresult aError) override;
void OnTakePictureComplete(uint8_t* aData, uint32_t aLength, const nsAString& aMimeType) override;
void OnTakePictureComplete(const uint8_t* aData, uint32_t aLength, const nsAString& aMimeType) override;
void AllocImpl();
void DeallocImpl();