From bca4d15bba37c865af1057c0f16b7dc30d5b3b06 Mon Sep 17 00:00:00 2001 From: shenpeixing Date: Thu, 26 Jun 2025 09:57:16 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E5=91=8A=E8=AD=A6=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: shenpeixing --- .../js/ani/vibrator/src/vibrator_ani.cpp | 35 ++++++------------- 1 file changed, 11 insertions(+), 24 deletions(-) diff --git a/frameworks/js/ani/vibrator/src/vibrator_ani.cpp b/frameworks/js/ani/vibrator/src/vibrator_ani.cpp index ddce5a0..358f2bd 100644 --- a/frameworks/js/ani/vibrator/src/vibrator_ani.cpp +++ b/frameworks/js/ani/vibrator/src/vibrator_ani.cpp @@ -751,34 +751,20 @@ static bool ParseEffectTypeAndParameters(ani_env *env, ani_object effect, Vibrat 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); + int32_t eventNum = vibrateInfo.vibratorPattern.eventNum; + auto events = vibrateInfo.vibratorPattern.events; + if (eventNum <= 0 || events == nullptr) { + MISC_HILOGW("Events is not need to free, event size:%{public}d", eventNum); return; } - auto patterns = &vibrateInfo.vibratorPattern; - if (patterns == nullptr) { - MISC_HILOGW("Patterns is not need to free, patterns is null"); - 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; + for (int32_t j = 0; j < eventNum; ++j) { + if (events[j].points != nullptr) { + free(events[j].points); + events[j].points = nullptr; } - 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; + free(events); + events = nullptr; } static void StartVibrationSync([[maybe_unused]] ani_env *env, ani_object effect, ani_object attribute) @@ -797,6 +783,7 @@ static void StartVibrationSync([[maybe_unused]] ani_env *env, ani_object effect, VibrateInfo vibrateInfo; if (!ParseEffectTypeAndParameters(env, effect, vibrateInfo)) { + FreeVibrateInfo(vibrateInfo); return; } if (!ParserParamFromVibrateAttribute(env, attribute, vibrateInfo)) { -- Gitee