diff --git a/interfaces/plugin/src/sensor_js.cpp b/interfaces/plugin/src/sensor_js.cpp index 43dd065ccf54183b84e39ccbb02c24d8f7812a65..579362c8221bf770a459472321528a7b1aa4e308 100644 --- a/interfaces/plugin/src/sensor_js.cpp +++ b/interfaces/plugin/src/sensor_js.cpp @@ -258,9 +258,8 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca { std::vector callbackInfos = g_onCallbackInfos[sensorTypeId]; std::vector::iterator iter; - for (iter = callbackInfos.begin(); iter != callbackInfos.end();) { + for (iter = callbackInfos.begin(); iter != callbackInfos.end(); ++iter) { if (*iter == nullptr || (*iter)->callback[0] == nullptr) { - HiLog::Error(LABEL, "%{public}s arg is null", __func__); continue; } napi_value sensorCallback = nullptr; @@ -271,14 +270,13 @@ static uint32_t RemoveCallback(napi_env env, int32_t sensorTypeId, napi_value ca delete *iter; *iter = nullptr; callbackInfos.erase(iter++); - if (callbackInfos.empty()) { - g_onCallbackInfos.erase(sensorTypeId); - return 0; - } - } else { - ++iter; + break; } } + if (callbackInfos.empty()) { + g_onCallbackInfos.erase(sensorTypeId); + return 0; + } g_onCallbackInfos[sensorTypeId] = callbackInfos; return callbackInfos.size(); }