Skip to content

Commit

Permalink
Fix crash
Browse files Browse the repository at this point in the history
  • Loading branch information
hung-eoh committed Jun 9, 2024
1 parent 4381305 commit 40d0299
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
26 changes: 17 additions & 9 deletions src/ERa/ERaParam.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -230,19 +230,19 @@ class ERaParam
void add_dynamic(char* value) {
this->free();
this->valuestring = value;
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STRING, true);
this->setTypeString();
}

void add_static(char* value) {
this->free();
this->valuestring = value;
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STATIC_STRING, true);
this->setTypeStaticString();
}

void add_static(const char* value) {
this->free();
this->valuestring = const_cast<char*>(value);
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STATIC_STRING, true);
this->setTypeStaticString();
}

template <typename T>
Expand Down Expand Up @@ -443,25 +443,25 @@ class ERaParam
void addParam(char* value) {
this->free();
this->valuestring = ERaStrdup(value);
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STRING, true);
this->setTypeString();
}

void addParam(const char* value) {
this->free();
this->valuestring = ERaStrdup(value);
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STRING, true);
this->setTypeString();
}

void addParam(cJSON* value) {
this->free();
this->valuestring = cJSON_PrintUnformatted(value);
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STRING, true);
this->setTypeString();
}

void addParam(const cJSON* value) {
this->free();
this->valuestring = cJSON_PrintUnformatted(value);
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STRING, true);
this->setTypeString();
}

void addParam(ERaDataJson& value) {
Expand All @@ -475,8 +475,16 @@ class ERaParam
::free(this->valuestring);
}
this->valuestring = nullptr;
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STRING, false);
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STATIC_STRING, false);
this->setTypeString();
this->setTypeStaticString();
}

void setTypeString() {
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STRING, (this->valuestring != nullptr));
}

void setTypeStaticString() {
this->setType(ERaParamTypeT::ERA_PARAM_TYPE_STATIC_STRING, (this->valuestring != nullptr));
}

void setType(uint8_t mask, bool value) {
Expand Down
8 changes: 4 additions & 4 deletions src/ERa/ERaProperty.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -697,14 +697,14 @@ void ERaProperty<Api>::handler(const char* id, const ERaParam& param) {
continue;
}
else {
if (pProp->allocPointer != nullptr) {
free(pProp->allocPointer);
pProp->allocPointer = nullptr;
}
if (pProp->value != nullptr) {
delete pProp->value;
pProp->value = nullptr;
}
if (pProp->allocPointer != nullptr) {
free(pProp->allocPointer);
pProp->allocPointer = nullptr;
}
pProp->report.deleteReport();
delete pProp;
pProp = nullptr;
Expand Down

0 comments on commit 40d0299

Please sign in to comment.