fix segfault when the devtype is null

This commit is contained in:
lnk
2025-07-01 18:40:05 +08:00
parent 7c190cb658
commit 5213bf2ab7
2 changed files with 48 additions and 6 deletions

View File

@@ -4427,6 +4427,14 @@ int parse_model_web(QMap<QString, icd_model*>* icd_model_map,const std::vector<s
return 0; // 确保函数有返回值
}
void delete_icd_model_map(QMap<QString, icd_model*>& map) { //lnk20250701防止内存泄漏
QMap<QString, icd_model*>::iterator it;
for (it = map.begin(); it != map.end(); ++it) {
delete it.value();
}
map.clear();
}
int parse_model_cfg_web()
{
std::vector<std::string> codes;//入参集合
@@ -4510,6 +4518,7 @@ int parse_model_cfg_web()
Set_xml_databaseinfo(model_id, tmnl_type, file_path, file_name, timestamp.year, timestamp.month, timestamp.day, timestamp.hour, timestamp.minute, timestamp.second);
}
}
delete_icd_model_map(icd_model_map);
return APR_SUCCESS;
}
catch (otl_exception& e)
@@ -4527,6 +4536,11 @@ char* parse_model_cfg_web_one(ied_t* ied, char* out_model)
ied_usr = (ied_usr_t*)ied->usr_ext;
if (strlen(ied_usr->dev_type) == 0) {
std::cerr << "parse_model_cfg_web_one warning: dev_type is empty" << std::endl;
return nullptr;
}
// 手动构建 JSON 字符串
std::string input_jstr = "[";
input_jstr += "\"" + std::string(ied_usr->dev_type) + "\"";
@@ -4572,11 +4586,11 @@ char* parse_model_cfg_web_one(ied_t* ied, char* out_model)
strncpy(out_model, model_id, 64);
out_model[63] = '\0';
}
return out_model;
break;//lnk20250701
}
}
delete_icd_model_map(icd_model_map);//lnk20250701
return NULL;
}
catch (otl_exception& e)
{
@@ -5250,7 +5264,6 @@ int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_i
}
} else {
printf("Error: sscanf failed. Invalid timestamp format.\n");
return -1;
}
}
@@ -5258,7 +5271,7 @@ int update_one_terminal_ledger(terminal* update, int i,ied_t* ied,int terminal_i
if(!ied_take){
chnl_usr = (chnl_usr_t*)apr_pcalloc(g_init_pool, sizeof(chnl_usr_t));
ied->channel[0].connect = chnl_usr;
g_pt61850app->chnl_counts++; //新增的需要添加
g_pt61850app->chnl_counts++; //新增的需要添加,假设一直添加失败,这里会一直递增到最大终端数,后续不再添加
}
else{
chnl_usr = (chnl_usr_t*)ied->channel[0].connect;