From 8c27feae254ee13b368afe741be6b6e41e641d48 Mon Sep 17 00:00:00 2001 From: shenpeixing Date: Fri, 20 Jun 2025 15:33:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9tdd=E7=9A=84crash=E9=97=AE?= =?UTF-8?q?=E9=A2=98=E4=B8=8E=E5=91=8A=E8=AD=A6=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shenpeixing --- .../taihe/author/src/ohos.vibrator.impl.cpp | 10 ++--- .../js/ani/vibrator/src/vibrator_ani.cpp | 41 +++++++++++++++++-- 2 files changed, 42 insertions(+), 9 deletions(-) diff --git a/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp index 14268ad..ebb2d56 100644 --- a/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp +++ b/frameworks/ets/taihe/author/src/ohos.vibrator.impl.cpp @@ -150,7 +150,7 @@ static bool ParseVibratorPattern(::ohos::vibrator::VibratorPattern pattern, Vibr { CALL_LOG_ENTER; vibrateInfo.vibratorPattern.time = pattern.time; - vibrateInfo.vibratorPattern.eventNum = pattern.events.size(); + vibrateInfo.vibratorPattern.eventNum = static_cast(pattern.events.size()); if (vibrateInfo.vibratorPattern.eventNum <= 0 || vibrateInfo.vibratorPattern.eventNum > EVENT_NUM_MAX) { MISC_HILOGE("length should not be less than or equal to 0 or greater than EVENT_NUM_MAX"); return false; @@ -183,7 +183,7 @@ static void PrintVibratorPattern(::ohos::vibrator::VibratorPattern &vibratorPatt } MISC_HILOGD("PrintVibratorPattern, time:%{public}d, eventNum:%{public}u", vibratorPattern.time, vibratorPattern.events.size()); - for (int32_t i = 0; i < vibratorPattern.events.size(); ++i) { + for (int32_t i = 0; i < static_cast(vibratorPattern.events.size()); ++i) { MISC_HILOGD("PrintVibratorPattern, type:%{public}d, time:%{public}d, duration:%{public}d, \ intensity:%{public}d, frequency:%{public}d, index:%{public}d, pointNum:%{public}u", static_cast(vibratorPattern.events[i].eventType), vibratorPattern.events[i].time, @@ -195,7 +195,7 @@ static void PrintVibratorPattern(::ohos::vibrator::VibratorPattern &vibratorPatt return; } ::taihe::array<::ohos::vibrator::VibratorCurvePoint> point = vibratorPattern.events[i].points.value(); - for (int32_t j = 0; j < vibratorPattern.events[i].points.value().size(); ++j) { + for (int32_t j = 0; j < static_cast(vibratorPattern.events[i].points.value().size()); ++j) { MISC_HILOGD("PrintVibratorPattern, time:%{public}d, intensity:%{public}d, frequency:%{public}d", point[j].time, point[j].intensity.value(), point[j].frequency.value()); } @@ -210,7 +210,7 @@ static bool CheckVibratorCurvePoint(const ::ohos::vibrator::VibratorEvent &event MISC_HILOGE("The points size is out of range, pointNum:%{public}u", event.points.value().size()); return false; } - for (int32_t j = 0; j < event.points.value().size(); ++j) { + for (int32_t j = 0; j < static_cast(event.points.value().size()); ++j) { if ((event.points.value()[j].time < 0) || (event.points.value()[j].time > event.duration.value())) { MISC_HILOGE("time in points is out of range, time:%{public}d", event.points.value()[j].time); return false; @@ -277,7 +277,7 @@ static bool CheckVibratorPatternParameter(::ohos::vibrator::VibratorPattern &vib MISC_HILOGE("The event num is out of range, eventNum:%{public}u", vibratorPattern.events.size()); return false; } - for (int32_t i = 0; i < vibratorPattern.events.size(); ++i) { + for (int32_t i = 0; i < static_cast(vibratorPattern.events.size()); ++i) { if (!CheckVibratorEvent(vibratorPattern.events[i])) { MISC_HILOGE("CheckVibratorEvent failed"); return false; diff --git a/frameworks/js/ani/vibrator/src/vibrator_ani.cpp b/frameworks/js/ani/vibrator/src/vibrator_ani.cpp index 9fe86ee..bb7f373 100644 --- a/frameworks/js/ani/vibrator/src/vibrator_ani.cpp +++ b/frameworks/js/ani/vibrator/src/vibrator_ani.cpp @@ -305,19 +305,19 @@ static bool GetPropertyAsDouble(ani_env* env, ani_object obj, const char* proper ani_boolean isUndefined = false; if (env->Object_GetPropertyByName_Ref(obj, propertyName, &propRef) != ANI_OK) { - MISC_HILOGE("GetPropertyAsDouble: Failed to get property '%{punlic}s'", propertyName); + MISC_HILOGE("GetPropertyAsDouble, failed to get property:%{public}s", propertyName); return false; } env->Reference_IsUndefined(propRef, &isUndefined); if (isUndefined) { - MISC_HILOGE("GetPropertyAsDouble: Property '%{punlic}s' is undefined", propertyName); + MISC_HILOGE("GetPropertyAsDouble, property:%{public}s is undefined", propertyName); return false; } if (env->Object_CallMethodByName_Double(static_cast(propRef), "doubleValue", nullptr, outValue) != ANI_OK) { - MISC_HILOGE("GetPropertyAsDouble: Failed to call 'doubleValue' on property '%{punlic}s'", propertyName); + MISC_HILOGE("GetPropertyAsDouble, failed to call doubleValue on property:%{public}s'", propertyName); return false; } @@ -401,7 +401,7 @@ static bool ParsePointsArray(ani_env *env, ani_object parentObject, VibratorEven return false; } - event.pointNum = static_cast(sizePoints); + event.pointNum = static_cast(sizePoints); if (static_cast(sizePoints) > 0) { if (!ParseVibratorCurvePointArray(env, static_cast(points), @@ -749,6 +749,38 @@ static bool ParseEffectTypeAndParameters(ani_env *env, ani_object effect, Vibrat return true; } +static void FreeVibrateInfo(VibrateInfo &vibrateInfo) +{ + int32_t patternSize = vibrateInfo.count; + if (patternSize <= 0) { + MISC_HILOGW("Patterns is not need to free, pattern size:%{public}d", patternSize); + return; + } + auto patterns = &vibrateInfo.vibratorPattern; + if (patterns == nullptr) { + MISC_HILOGW("Patterns is not need to free, patterns is"); + return; + } + for (int32_t i = 0; i < patternSize; ++i) { + int32_t eventNum = patterns[i].eventNum; + if ((eventNum <= 0) || (patterns[i].events == nullptr)) { + MISC_HILOGW("Events is not need to free, event size:%{public}d", eventNum); + continue; + } + auto events = patterns[i].events; + for (int32_t j = 0; j < eventNum; ++j) { + if (events[j].points != nullptr) { + free(events[j].points); + events[j].points = nullptr; + } + } + free(events); + events = nullptr; + } + free(patterns); + patterns = nullptr; +} + static void StartVibrationSync([[maybe_unused]] ani_env *env, ani_object effect, ani_object attribute) { ani_namespace ns; @@ -768,6 +800,7 @@ static void StartVibrationSync([[maybe_unused]] ani_env *env, ani_object effect, return; } if (!ParserParamFromVibrateAttribute(env, attribute, vibrateInfo)) { + FreeVibrateInfo(vibrateInfo); ThrowBusinessError(env, PARAMETER_ERROR, "ParserParamFromVibrateAttribute failed!"); return; } -- Gitee