修复 getFileSize() 内存泄露的问题

更新 updateCacheFileName()
This commit is contained in:
CSSC-WORK\murmur 2023-07-29 22:09:35 +08:00
parent 4dbcd25af8
commit 7d06ab7e7b
2 changed files with 22 additions and 25 deletions

View File

@ -66,11 +66,6 @@ int trDataTolog(uint8_t *din, size_t len, uint8_t isTx)
}
}
RT_WEAK int set_cfg(const char *k, const char*v)
{
return;
}
//3.2.1双模通信功能
//1为TT通信0为BD短报文通信
void setCommMode(int isTT)
@ -167,7 +162,7 @@ void upSend_thread_entry(void* parameter)
//cache to file
LOG_W("TT is not ready, try to cache %d bytes data to file.",msg->len);
cacheDataToFile(msg->data, msg->len);
return -RT_ERROR;
return ;
}
@ -181,7 +176,7 @@ void upSend_thread_entry(void* parameter)
packInit(&cfg, fin, 0); //写入配置
cfg.fcurpiece[0] = 1;
cfg.fallpiece[0] = 1;
size_t rst = packMsg(&cfg, msg->data, msg->len, dout);
size_t rst = packMsg(&cfg, msg->data, msg->len, dout);//packMsgs
LOG_HEX("upSend", 27, dout, rst);
if (rst)
{
@ -200,7 +195,7 @@ void upSend_thread_entry(void* parameter)
cacheDataToFile(msg->data, msg->len);
}
}
return 0;
return ;
}
/**
*
@ -234,7 +229,7 @@ RT_WEAK int upSend(uint8_t *din, size_t len)
//
// //此函数有打包操作,需线程操作
//// LOG_D("upsend.");
//// return 0;
// return 0;
//
static SMSG msg;
memset(&msg, 0, sizeof(SMSG));
@ -861,6 +856,7 @@ unsigned long getFileSize(char *file)
{
struct stat stat;
char *fullpath, *path;
unsigned long rst=0;
#ifdef DFS_USING_WORKDIR
/* open current working directory */
@ -873,12 +869,11 @@ unsigned long getFileSize(char *file)
rt_memset(&stat, 0, sizeof(struct stat));
if (dfs_file_stat(fullpath, &stat) == 0)
{
return (unsigned long) stat.st_size;
}
else
{
return 0;
rst = stat.st_size;
}
rt_free(fullpath);
rt_free(path);
return rst;
}
void d_getFileSize(int argc, char ** argv)
@ -960,12 +955,12 @@ int cacheDataToFile(uint8_t *din, size_t len)
}
// cnt += len;
close(fd);
size_t size = getFileSize(f);
LOG_I("cached %d bytes data to '%s', new size is %d bytes.",len,f,size);
unsigned long size = getFileSize(f);
LOG_I("cached %d bytes data to '%s', new size is %ld bytes.",len,f,size);
if (size > scfg.maxSizePerFile) {
postFileInfo(f,0);//加入待发列表
getNewCacheFileName(f);//更新文件名
updateCacheFileName();//更新文件名
}
}
@ -987,7 +982,7 @@ void parseRS232(uint8_t *din, size_t len)
//有HEX有ASCII统一按HEX解析
//部分数据以10字节20字符的0数据开始如深度查询心跳包等
//处理思路是先不管前导0对应指令手动加前导数据
uint8_t asciiHead[]={0x41, 0x54, 0x2B, 0x53, 0x4E, 0x44,};//"AT+SND"
// uint8_t asciiHead[]={0x41, 0x54, 0x2B, 0x53, 0x4E, 0x44,};//"AT+SND"
uint8_t hexHead[]={0x5a, 0xa5};//"5AA5"
//由于帧头有多种且ascii和hex混发无法处理粘包
@ -1026,7 +1021,7 @@ void parseRS232(uint8_t *din, size_t len)
}
else//如果不是ASCII则统一按HEX计// if (memcmp(din,hexHead,sizeof(hexHead)) == 0)
{
//hex
//bin
LOG_I("type = BIN");
char tmp[200]="";
trDataTolog(bytes2str(din, len, 16, " ", tmp), strlen(tmp), 0);

View File

@ -391,7 +391,7 @@ size_t isInByte(uint8_t *din, size_t len, uint8_t *s, size_t slen, uint8_t *dout
* @param fin
* @return
*/
char *getNewCacheFileName(char *fin)
void updateCacheFileName()
{
char f[60]="";
char rootDir[22] = ROOT_PATH_DATA;
@ -415,8 +415,8 @@ char *getNewCacheFileName(char *fin)
// strcpy(cfname,f);
updateLstFile(f);
strcpy(fin,f);
return fin;
// strcpy(fin,f);
// return fin;
}
@ -432,8 +432,9 @@ char *getLstCacheFileName(char *fin)
// getNewCacheFileName(fin);
// }
char f[60];
if (!getLstFile(f)) {
getNewCacheFileName(fin);
while (!getLstFile(f)) {
updateCacheFileName();
rt_thread_mdelay(1000);
}
strcpy(fin,f);
return fin;
@ -445,7 +446,8 @@ void d_gcf()
{
char f[60];
LOG_D("--%s",getLstCacheFileName(f));
LOG_D("--%s",getNewCacheFileName(f));
updateCacheFileName();
LOG_D("--%s",getLstCacheFileName(f));
}
MSH_CMD_EXPORT(d_gcf,cache file);