diff options
| author | wangyouzhan <[email protected]> | 2019-07-29 13:52:09 +0800 |
|---|---|---|
| committer | wangyouzhan <[email protected]> | 2019-07-29 13:52:09 +0800 |
| commit | 5b9a8da5ba6b8ecea1f589487a4a736b24e25979 (patch) | |
| tree | b540a8f5273b758efb55802e0457543f13070a7d | |
| parent | 41778e0e78f3e0de4e04bebfc168de2d85f86148 (diff) | |
修改内存泄漏
| -rw-r--r-- | src/comm_audit.cpp | 85 |
1 files changed, 25 insertions, 60 deletions
diff --git a/src/comm_audit.cpp b/src/comm_audit.cpp index 5ffaa05..e570a70 100644 --- a/src/comm_audit.cpp +++ b/src/comm_audit.cpp @@ -14,6 +14,7 @@ #include <errno.h>
#include <stdlib.h>
#include <string.h>
+#include <stdio.h>
#include "project_requirement.h"
@@ -93,8 +94,8 @@ int get_ip_coun(char * filename, char *ip_address, char ** name_en) if (entry_data.has_data)
{
- *name_en = (char *)malloc(sizeof(entry_data.data_size + 1));
- memset(*name_en, '\0', sizeof(entry_data.data_size + 1));
+ *name_en = (char *)malloc(entry_data.data_size + 1);
+ memset(*name_en, '\0', (entry_data.data_size + 1));
memcpy(*name_en, entry_data.utf8_string, entry_data.data_size);
//printf ("%s\n", name_en);
}
@@ -268,13 +269,6 @@ void iterate_cb(const uchar * key, uint size, void * data, void *arg) char writefile[50];
writefile[0]='\0';
- // string write_path = g_comm_prog_configure.upload_log_path;
- // if (write_path[write_path.size() - 1] != '/')
- // write_path+='/';
- // #ifdef LOG_DEBUG
- // cout<<"write_path:"<<write_path<<endl;
- // #endif
-
string tmp_log_path = g_comm_prog_configure.tmp_log_path;
if (tmp_log_path[tmp_log_path.size() - 1] != '/')
tmp_log_path+='/';
@@ -299,22 +293,6 @@ void iterate_cb(const uchar * key, uint size, void * data, void *arg) fclose(fp);
fp = NULL;
- /*
- if(log_nums == 0 && log == 1)
- {
- g_comm_prog_para.last_send_time = time(NULL);
-
- char cmd[200] = {0};
- sprintf(cmd, "cd %s; gzip -q %s-%d.txt; mv *.gz %s%s", g_comm_prog_configure.tmp_log_path, writetime, times-1, write_path.c_str(), FDIR);
- // system(cmd);
- FILE * ret = popen(cmd, "w");
- if(!ret)
- MESA_handle_runtime_log(g_comm_prog_para.log_handle, RLOG_LV_FATAL, "FATAL", "%s IS FAILED! ERROR NUM IS %s",cmd, strerror(errno));
- else
- MESA_handle_runtime_log(g_comm_prog_para.log_handle, RLOG_LV_INFO, "INFO", "Pack %s/%s.gz is submit.", FDIR, writetime);
- pclose(ret);
- }
- */
if(MESA_htable_del(g_comm_prog_para.htable_handle[thread_seq][1], key, size, NULL) < 0)
{
@@ -341,20 +319,11 @@ void * thread_time(void * pParam) localtime_r(&sTime, &stm);
last = stm.tm_hour * 10000 + stm.tm_min * 100 + stm.tm_sec;
- // sprintf(FDIR, "%d-%02d-%02d", stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday);
- // char mkdir[50]={0};
- // sprintf(mkdir, "mkdir -p %s/%s", g_comm_prog_configure.upload_log_path, FDIR);
- // FILE * ret = popen(mkdir, "w");
- // if(!ret)
- // MESA_handle_runtime_log(g_comm_prog_para.log_handle, RLOG_LV_FATAL, "FATAL", "%s FAILED! ERROR IS %s",mkdir, strerror(errno));
- // pclose(ret);
-
char FNAME[10];
char TXT[8];
sprintf(FNAME, "%d-%d-%d", stm.tm_hour, stm.tm_min, stm.tm_sec);
//sprintf(TXT, "%d-%d-%d", stm.tm_hour, stm.tm_min, stm.tm_sec);
sprintf(TXT, "%d%02d%02d", stm.tm_year+1900, stm.tm_mon+1, stm.tm_mday);
- //sprintf(etime, "%d-%d-%d %d:%d:%d", ptm.tm_year+1900, ptm.tm_mon+1, ptm.tm_mday, ptm.tm_hour, ptm.tm_min, ptm.tm_sec);
// times = 1;
log_nums = 0;
@@ -395,33 +364,10 @@ void * thread_time(void * pParam) localtime_r(&eTime, &ptm);
now = ptm.tm_hour * 10000 + ptm.tm_min * 100 + ptm.tm_sec;
-
if(log == 1)
{
if(now - last >= g_comm_prog_configure.write_interval * 100)
{
- /*
- char cmd[200] = {0};
- string log_path = g_comm_prog_configure.upload_log_path;
- if (log_path[log_path.size() - 1] != '/')
- log_path+='/';
-#ifdef LOG_DEBUG
-cout<<"log_path:"<<log_path<<endl;
-#endif
-
-sprintf(cmd, "cd %s; count=`ls|grep .txt|wc -l`; if [[ $count -gt 0 ]]; then tar -zcf %s%s/%s.tar.gz *.txt; rm -f *.txt; fi;", \
-g_comm_prog_configure.tmp_log_path, log_path.c_str(), FDIR, FNAME);
-#ifdef LOG_DEBUG
-cout<<cmd<<endl;
-#endif
-
-FILE * ret = popen(cmd, "w");
-if(!ret)
-MESA_handle_runtime_log(g_comm_prog_para.log_handle, RLOG_LV_FATAL, "FATAL", "MKDIR IS FAILED! ERROR IS %s",strerror(errno));
-else
-MESA_handle_runtime_log(g_comm_prog_para.log_handle, RLOG_LV_INFO, "INFO", "Pack %s/%s.tar.gz is submit.", FDIR, FNAME);
-pclose(ret);
-*/
times++;
g_comm_prog_para.last_send_time = time(NULL);
}
@@ -433,7 +379,6 @@ pclose(ret); }
}
return NULL;
-
}
@@ -491,7 +436,6 @@ static long search_cb(void* data, const uchar* key, uint size, void* arg) }
-
int judge_ip_location(unsigned int inner_ip, char ** inner_name_en, unsigned int ext_ip, char ** ext_name_en)
{
char innerIP[IPLEN] = {0};
@@ -561,8 +505,30 @@ void time_mode_op(struct streaminfo* a_stream, int thread_seq, void * a_packet, }
else if(judge_res == 2) //全都是境内IP,不做记录,直接返回
{
+ if(NULL != inner_name_en)
+ {
+ free(inner_name_en);
+ inner_name_en = NULL;
+ }
+ if(NULL != ext_name_en)
+ {
+ free(ext_name_en);
+ ext_name_en = NULL;
+ }
+ free(value);
+ value = NULL;
return ;
}
+ if(NULL != inner_name_en)
+ {
+ free(inner_name_en);
+ inner_name_en = NULL;
+ }
+ if(NULL != ext_name_en)
+ {
+ free(ext_name_en);
+ ext_name_en = NULL;
+ }
}
}
if(a_stream->type == STREAM_TYPE_TCP)
@@ -711,7 +677,6 @@ char COMM_AUDIT_ENTRY(struct streaminfo *a_stream, void **pme, int thread_seq, v ret = APP_STATE_DROPME;
break;
}
-
return ret;
}
|
