fix segfault when the ledger incomplete
This commit is contained in:
@@ -1450,8 +1450,18 @@ int parse_rpt_log_ini()
|
||||
|
||||
//ied_usr->LD_info[cpuno].LD_name = apr_pstrdup(g_init_pool, str);
|
||||
|
||||
//已经分配过内存,直接复制到里面
|
||||
apr_snprintf(ied_usr->LD_info[cpuno].LD_name, sizeof(ied_usr->LD_info[cpuno].LD_name), tmp, cpuno + 1);
|
||||
//已经分配过内存,直接复制到里面,在台账初始化有一句ied_usr->LD_info[cpuno - 1].LD_name = (char *)apr_palloc(g_init_pool, 256);
|
||||
//调试用
|
||||
printf("%s使用内存地址 LD_name[%d]: %p\n", ied_usr->terminal_id, cpuno, (void*)ied_usr->LD_info[cpuno].LD_name);
|
||||
|
||||
//添加判断,有的监测点没有cpuno为2,直接申请了LD_info[1],没申请LD_info[0]
|
||||
if(ied_usr->LD_info[cpuno].LD_name == NULL){
|
||||
printf("this ld_info didn't palloc space ,maybe this ledger has problem!");
|
||||
DIY_ERRORLOG("process","终端%s的监测点序号为%d的监测点没有在写入台账时申请空间,所以无法初始化报告,台账可能存在缺失,跳过这个监测点的报告初始化操作",ied_usr->terminal_id,cpuno + 1);
|
||||
continue;//跳过防止崩溃
|
||||
}
|
||||
|
||||
apr_snprintf(ied_usr->LD_info[cpuno].LD_name, 256, tmp, cpuno + 1);//注意拷贝大小,容易段错误,
|
||||
|
||||
delete[] tmp;
|
||||
|
||||
@@ -4244,6 +4254,8 @@ int parse_device_cfg_web()
|
||||
//ied_usr->LD_info[cpuno - 1].LD_name = apr_pstrdup(g_init_pool, str);//将 str 中的格式化字符串复制到内存池 g_init_pool 中。ied_usr->LD_info[cpuno - 1].LD_name 存储了这个字符串的副本,LD_name 现在是 PQMonitorPQM{cpuno} 的形式。
|
||||
// 从 g_init_pool 内存池中分配固定 256 字节的内存
|
||||
ied_usr->LD_info[cpuno - 1].LD_name = (char *)apr_palloc(g_init_pool, 256);
|
||||
//调试用,申请的地址
|
||||
printf("%s分配内存地址 LD_name[%d]: %p\n", ied_usr->terminal_id, cpuno - 1, (void*)ied_usr->LD_info[cpuno - 1].LD_name);
|
||||
|
||||
// 清空内存,防止残留数据
|
||||
memset(ied_usr->LD_info[cpuno - 1].LD_name, 0, 256);
|
||||
@@ -5573,6 +5585,14 @@ int parse_rpt_log_ini_one(ied_t* ied)
|
||||
apr_snprintf(str, sizeof(str), tmp, cpuno + 1);
|
||||
|
||||
//调试
|
||||
printf("%s使用内存地址 LD_name[%d]: %p\n", ied_usr->terminal_id, cpuno, (void*)ied_usr->LD_info[cpuno].LD_name);
|
||||
//添加判断,有的监测点没有cpuno为2,直接申请了LD_info[2-1],没申请LD_info[0]
|
||||
if(ied_usr->LD_info[cpuno].LD_name == NULL){
|
||||
printf("this ld_info didn't palloc space ,maybe this ledger has problem!");
|
||||
DIY_ERRORLOG("process","终端%s的监测点序号为%d的监测点没有在写入台账时申请空间,所以无法初始化报告,台账可能存在缺失,跳过这个监测点的报告初始化操作",ied_usr->terminal_id,cpuno + 1);
|
||||
continue;//跳过防止崩溃
|
||||
}
|
||||
|
||||
printf("logini ied_usr->LD_info[cpuno - 1].LD_name: %s\n", ied_usr->LD_info[cpuno].LD_name);
|
||||
|
||||
delete[] tmp;//Get_IED中分配了内存,使用后删除
|
||||
|
||||
Reference in New Issue
Block a user