From 0ac74678fd584a1db089b90ab8892c0a39b0376b Mon Sep 17 00:00:00 2001 From: Oliver Wolff Date: Tue, 24 Apr 2018 10:52:43 +0200 Subject: winrt: Do not use CoTaskMemFree as image cleanup function CoTaskMemFree is declared __stdcall. This declaration causes a stack maintenance behavior (called function pops its own arguments from the stack) that breaks release builds and leads to crashes. By wrapping that function into our own function (which is by default __cdecl) we get the wanted stack maintenance behavior (calling function pops arguments from the stack) and thus avoid these crashes. Task-number: QTBUG-63016 Change-Id: Ibd36f4fc2680351bf41c2991e9b3f1723bb19eab Reviewed-by: Andre de la Rocha Reviewed-by: Maurice Kalinowski Reviewed-by: VaL Doroshchuk (cherry picked from commit 6a2f332821ea3d8d4f6c11050d592aef0ad4df7f) --- src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp index 54f4b103b..f4903c5a1 100644 --- a/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp +++ b/src/plugins/winrt/qwinrtcameraimagecapturecontrol.cpp @@ -106,6 +106,12 @@ struct CaptureRequest ComPtr op; }; +// Do not use CoTaskMemFree directly for image cleanup as it leads to crashes in release +static void freeImageData(void *data) +{ + CoTaskMemFree(data); +} + class QWinRTCameraImageCaptureControlPrivate { public: @@ -296,7 +302,7 @@ HRESULT QWinRTCameraImageCaptureControl::onCaptureCompleted(IAsyncAction *asyncI hr = frame->get_PixelWidth(&pixelWidth); Q_ASSERT_SUCCEEDED(hr); const QImage image(pixelData, pixelWidth, pixelHeight, QImage::Format_RGBA8888, - reinterpret_cast(&CoTaskMemFree), pixelData); + reinterpret_cast(&freeImageData), pixelData); emit imageCaptured(request.id, image); QWinRTImageEncoderControl *imageEncoderControl = static_cast(d->cameraControl->imageEncoderControl()); -- cgit v1.2.3