This is our old Q&A Site. Please post any new questions and answers at ask.wireshark.org.

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's gravatar image

lipeng5555
11112
accept rate: 0%

edited 28 Nov '13, 12:22

Guy%20Harris's gravatar image

Guy Harris ♦♦
17.4k335196

Be the first one to answer this question!
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×23
×18
×3

question asked: 28 Nov '13, 01:18

question was seen: 1,789 times

last updated: 28 Nov '13, 12:22

p​o​w​e​r​e​d by O​S​Q​A