i'am use libwireshark 1.10.3,i find memory leak,is it any question with my program
XJ_DISSECT_PKT* xj_dissect_packet()
{
#ifdef XJ_DISSECT_PACKET_LINUX_DEF
if (!g_xj_process_policies_called)
{
init_process_policies();//初始化本地权限
g_xj_process_policies_called = true;
}
#endif
if(!g_binitepan)
{
epan_init(register_all_protocols, register_all_protocol_handoffs,
NULL, NULL, NULL, NULL, NULL, NULL);
cleanup_dissection();//clean up environment
init_dissection();//init dissect environment
g_binitepan = true;
//tap_queue_init(&edt);//队列
}
frame_data *fdata;
epan_dissect_t *edt;
wtap_pkthdr pseudo_header;
pseudo_header.interface_id = 0;
pseudo_header.caplen = 0;
pseudo_header.len = -1;
pseudo_header.pkt_encap = 1;
pseudo_header.pack_flags = 0;
pseudo_header.drop_count = 0;
pseudo_header.opt_comment = NULL;
fdata = (frame_data*)g_new(frame_data, 1);
memset(fdata, 0, sizeof(frame_data));
fdata->pfd = NULL;
fdata->num = 1;
fdata->interface_id = 0;
fdata->pkt_len = DATA_LEN;
fdata->cap_len = DATA_LEN;
fdata->cum_bytes = 0;
fdata->file_off = 0;
fdata->subnum = 0;
fdata->lnk_t = WTAP_ENCAP_ETHERNET;
fdata->flags.encoding = PACKET_CHAR_ENC_CHAR_ASCII;
fdata->flags.visited = 0;
fdata->flags.marked = 0;
fdata->flags.ref_time = 0;
fdata->color_filter = NULL;
fdata->abs_ts.secs = 0;
fdata->abs_ts.nsecs = 0;
fdata->opt_comment = NULL;
nstime_t elapsed_time; /* Elapsed time */
nstime_t first_ts;
nstime_t prev_dis_ts;
nstime_t prev_cap_ts;
guint32 cum_bytes = 0;
nstime_set_zero(&elapsed_time);
nstime_set_zero(&first_ts);
nstime_set_zero(&prev_dis_ts);
nstime_set_zero(&prev_cap_ts);
edt = epan_dissect_new(TRUE, TRUE);
//frame_data_set_before_dissect(fdata, &elapsed_time, &first_ts, &prev_dis_ts, &prev_cap_ts);
epan_dissect_run(edt, &pseudo_header, xjdata, fdata, NULL);
epan_dissect_free(edt);
//frame_data_cleanup(fdata);
frame_data_destroy(fdata);
g_free(fdata);
//cleanup_dissection();
printf("successful call xj_dissect_packet...\n");
return NULL;
}
void MySleep(UINT nmilliseconds)
{
#ifdef OS_WINDOWS
//Sleep(nmilliseconds);
#endif
#ifdef OS_LINUX
timeval tm;
tm.tv_sec = nmilliseconds / 1000;
tm.tv_usec = (nmilliseconds % 1000) * 1000;
int nret=select(0, 0, 0, 0, &tm);
#endif
}
int main(int argc, char argv[])
{
XJ_DISSECT_PKT pXjstruct = NULL;
while (!g_bExit)
{
pXjstruct = xj_dissect_packet();
xj_cleanup_packet(pXjstruct);//释放资源
MySleep(50);
}
if (g_binitepan)
{
cleanup_dissection();
epan_cleanup();
}
return 0;
}
asked 28 Nov ‘13, 01:18
lipeng5555
11●1●1●2
accept rate: 0%
edited 28 Nov ‘13, 12:22
Guy Harris ♦♦
17.4k●3●35●196