fix segfault when the devtype is null
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -905,11 +905,15 @@ void process_ledger_update(trigger_update_xml_t *ledger_update_xml)
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "终端 id: %s 台账更新失败,无法写入台账", update[i].terminal_id);
|
||||
send_reply_to_kafka_c(update[i].guid, "2", msg);
|
||||
|
||||
clearIed(ied);//添加失败清空整个ied
|
||||
|
||||
return ;
|
||||
}
|
||||
//3-写入台账内容///////////////////////////////////
|
||||
|
||||
//4-配置映射文件//////////////////////////////
|
||||
char model[64];
|
||||
char model[64] = {0};
|
||||
// 获取模型ID,检查是否返回 NULL
|
||||
parse_model_cfg_web_one(ied,&model);//存储在/FeProject/dat/
|
||||
|
||||
@@ -923,6 +927,9 @@ void process_ledger_update(trigger_update_xml_t *ledger_update_xml)
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "终端 id: %s 台账更新失败,没有找到装置型号", update[i].terminal_id);
|
||||
send_reply_to_kafka_c(update[i].guid, "2", msg);
|
||||
|
||||
clearIed(ied);//添加失败清空整个ied
|
||||
|
||||
return ;
|
||||
}
|
||||
char full_path[128];
|
||||
@@ -1001,6 +1008,9 @@ void process_ledger_update(trigger_update_xml_t *ledger_update_xml)
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "终端 id: %s 台账更新失败,台账无法写入", update[i].terminal_id);
|
||||
send_reply_to_kafka_c(update[i].guid, "2", msg);
|
||||
|
||||
clearIed(ied);//添加失败清空整个ied
|
||||
|
||||
return ;
|
||||
}
|
||||
//3-写入台账内容////////////////////////////////////////////
|
||||
@@ -1021,6 +1031,9 @@ void process_ledger_update(trigger_update_xml_t *ledger_update_xml)
|
||||
char msg[256];
|
||||
snprintf(msg, sizeof(msg), "终端 id: %s 台账更新失败,没有找到装置型号", update[i].terminal_id);
|
||||
send_reply_to_kafka_c(update[i].guid, "2", msg);
|
||||
|
||||
clearIed(ied);//添加失败清空整个ied
|
||||
|
||||
return ;
|
||||
}
|
||||
char full_path[128];
|
||||
@@ -1378,8 +1391,16 @@ void CheckAllConnectedChannel()
|
||||
do {
|
||||
chnl_usr = g_pt61850app->chnl_usr[chnl_sequence_no];
|
||||
chnl_sequence_no = (chnl_sequence_no+1) % g_pt61850app->chnl_counts;
|
||||
|
||||
if (chnl_usr == NULL) continue; // 安全防护lnk20250701
|
||||
|
||||
} while ( (g_onlyIP[0]!=0) && (strcmp(g_onlyIP,chnl_usr->ip_str)!=0) );
|
||||
|
||||
if (chnl_usr == NULL || chnl_usr->chnl == NULL || chnl_usr->chnl->ied == NULL || chnl_usr->chnl->ied->usr_ext == NULL) {
|
||||
printf("chnl_usr or nested member is NULL, skip...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if(chnl_usr->m_state == CHANNEL_CONNECTED)
|
||||
{
|
||||
|
||||
@@ -1427,8 +1448,16 @@ void CheckNextNotConnectedChannel()
|
||||
do {
|
||||
chnl_usr = g_pt61850app->chnl_usr[chnl_total_no];
|
||||
chnl_total_no = (chnl_total_no+1) % g_pt61850app->chnl_counts;
|
||||
|
||||
if (chnl_usr == NULL) continue; // 安全防护lnk20250701
|
||||
|
||||
} while ( (g_onlyIP[0]!=0) && (strcmp(g_onlyIP,chnl_usr->ip_str)!=0) );
|
||||
|
||||
if (chnl_usr == NULL || chnl_usr->chnl == NULL || chnl_usr->chnl->ied == NULL || chnl_usr->chnl->ied->usr_ext == NULL) {
|
||||
printf("chnl_usr or nested member is NULL, skip...\n");
|
||||
return;
|
||||
}
|
||||
|
||||
//终端日志的key,lnk20250526
|
||||
char full_key_t_c[256]; // 分配足够空间
|
||||
char full_key_t_d[256]; // 分配足够空间
|
||||
|
||||
Reference in New Issue
Block a user