From 5b5f897494352e6040a9a745b0b5b9674ecd4b29 Mon Sep 17 00:00:00 2001 From: yuanjinghua Date: Sun, 17 Mar 2024 17:08:53 +0800 Subject: [PATCH] New Feature. bugfix for dangling pointer in TDD testcases of ScreenCapture Signed-off-by: yuanjinghua Change-Id: Id24c8d315233fb59c07e572a16d419f88df9f948 --- .../native/capi/screencapture/native_avscreen_capture.cpp | 3 +++ frameworks/native/screen_capture/screen_capture_impl.cpp | 2 +- .../screen_capture_test/capi/src/screen_capture_capi_mock.cpp | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp index c23e2fe12..666ae2bac 100644 --- a/frameworks/native/capi/screencapture/native_avscreen_capture.cpp +++ b/frameworks/native/capi/screencapture/native_avscreen_capture.cpp @@ -747,6 +747,7 @@ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetStateCallback(struct OH_AVScre OH_AVScreenCapture_OnStateChange callback, void *userData) { CHECK_AND_RETURN_RET_LOG(capture != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input capture is nullptr!"); + CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input stateCallback is nullptr!"); struct ScreenCaptureObject *screenCaptureObj = reinterpret_cast(capture); CHECK_AND_RETURN_RET_LOG(screenCaptureObj->screenCapture_ != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "screenCapture_ is null"); @@ -765,6 +766,7 @@ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetErrorCallback(struct OH_AVScre OH_AVScreenCapture_OnError callback, void *userData) { CHECK_AND_RETURN_RET_LOG(capture != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input capture is nullptr!"); + CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input errorCallback is nullptr!"); struct ScreenCaptureObject *screenCaptureObj = reinterpret_cast(capture); CHECK_AND_RETURN_RET_LOG(screenCaptureObj->screenCapture_ != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "screenCapture_ is null"); @@ -782,6 +784,7 @@ OH_AVSCREEN_CAPTURE_ErrCode OH_AVScreenCapture_SetDataCallback(struct OH_AVScree OH_AVScreenCapture_OnBufferAvailable callback, void *userData) { CHECK_AND_RETURN_RET_LOG(capture != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input capture is nullptr!"); + CHECK_AND_RETURN_RET_LOG(callback != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "input dataCallback is nullptr!"); struct ScreenCaptureObject *screenCaptureObj = reinterpret_cast(capture); CHECK_AND_RETURN_RET_LOG(screenCaptureObj->screenCapture_ != nullptr, AV_SCREEN_CAPTURE_ERR_INVALID_VAL, "screenCapture_ is null"); diff --git a/frameworks/native/screen_capture/screen_capture_impl.cpp b/frameworks/native/screen_capture/screen_capture_impl.cpp index facc593f3..c25f8316f 100644 --- a/frameworks/native/screen_capture/screen_capture_impl.cpp +++ b/frameworks/native/screen_capture/screen_capture_impl.cpp @@ -69,7 +69,7 @@ ScreenCaptureImpl::~ScreenCaptureImpl() int32_t ScreenCaptureImpl::Release() { - MEDIA_LOGD("ScreenCaptureImpl:0x%{public}06" PRIXPTR " CheckScreenCapturePermssion in", FAKE_POINTER(this)); + MEDIA_LOGD("ScreenCaptureImpl:0x%{public}06" PRIXPTR " Release in", FAKE_POINTER(this)); CHECK_AND_RETURN_RET_LOG(screenCaptureService_ != nullptr, MSERR_NO_MEMORY, "screen capture service does not exist.."); screenCaptureService_->Release(); diff --git a/test/unittest/screen_capture_test/capi/src/screen_capture_capi_mock.cpp b/test/unittest/screen_capture_test/capi/src/screen_capture_capi_mock.cpp index fb6ce9d01..0f6144579 100644 --- a/test/unittest/screen_capture_test/capi/src/screen_capture_capi_mock.cpp +++ b/test/unittest/screen_capture_test/capi/src/screen_capture_capi_mock.cpp @@ -191,7 +191,9 @@ int32_t ScreenCaptureCapiMock::Release() { UNITTEST_CHECK_AND_RETURN_RET_LOG(screenCapture_ != nullptr, MSERR_INVALID_OPERATION, "screenCapture_ == nullptr"); DelCallback(screenCapture_); - return OH_AVScreenCapture_Release(screenCapture_); + int32_t ret = OH_AVScreenCapture_Release(screenCapture_); + screenCapture_ = nullptr; + return ret; } int32_t ScreenCaptureCapiMock::SetMicrophoneEnabled(bool isMicrophone) -- Gitee