tcpdump mailing list archives

Possible memory leak


From: Flavio Truzzi <flaviotruzzi () gmail com>
Date: Wed, 10 Nov 2010 10:40:03 -0200

Hi, I'm getting a memory leak in the following code, I made it to iterate
through multiple files, I don't know where it leaks...


-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------
do {

        getline(LArquivos,filename);
        cout << filename << endl;
        if (filename == "") break;

        for (it = VsatXAcc.begin(); it != VsatXAcc.end(); ++it) {
//            cout << "VSAT: " << it->first << endl;


            handle = pcap_open_offline(filename.c_str(),errbuff);

            if (!handle) {
                cout << errbuff << endl;
                return -1;
            }

            if (pcap_compile(handle,&filtro,it->second->filter.c_str(),0,0)
== -1) {
                cout << "Problema ao compilar filtro" << endl;
                return -1;
            }

            if (pcap_setfilter(handle, &filtro) == -1) {
                cout << "Problema ao aplicar filtro" << endl;
                return -1;
            }


            // Itera no arquivo
            bool first = true;
            do {

                packet = pcap_next(handle,&header);
                if (packet == NULL) break;
                if (first) {
                    it->second->lastTime =
header.ts.tv_sec*1000000.0+header.ts.tv_usec;
                    first = false;
                }
                if (!packet) break;

                it->second->size += header.len;
                it->second->size2 += (header.len)*(header.len);
                delta =
(header.ts.tv_sec*1000000.0+header.ts.tv_usec)-it->second->lastTime;
                if (delta > 0) {
                    it->second->interArrival += delta;
                    it->second->interArrival2 += delta*delta;
                }
                it->second->lastTime =
header.ts.tv_sec*1000000.0+header.ts.tv_usec;
                it->second->n++;

            } while (packet != NULL);

            pcap_freecode(&filtro);
            pcap_close(handle);


        }



    } while (!LArquivos.eof());
----------------------------------------------------------------------------------------------------------------------------------
Valgrind output ....
Don't worry with the 59,533 (28,560 direct, 30,973 indirect) bytes in 357
blocks are definitely lost in loss record 21 of 22  (Its not a leak, I use
that and close the program later).

I want to discover where is this leak ->  118,336 bytes in 357 blocks are
definitely lost in loss record 22 of 22 by main (main.cpp:73)
line 73 :     if (pcap_setfilter(handle, &filtro) == -1)

==7748== Memcheck, a memory error detector
==7748== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al.
==7748== Using Valgrind-3.6.0 and LibVEX; rerun with -h for copyright info
==7748== Command:
/home/sherlock/NetBeansProjects/Hounder/dist/Debug/GNU-Linux-x86/hounder
==7748==
==7748== FILE DESCRIPTORS: 4 open at exit.
==7748== Open file descriptor 18:
==7748== <inherited from parent>
==7748==
==7748== Open file descriptor 2: /dev/pts/0
==7748== <inherited from parent>
==7748==
==7748== Open file descriptor 1: /dev/pts/0
==7748== <inherited from parent>
==7748==
==7748== Open file descriptor 0: /dev/pts/0
==7748== <inherited from parent>
==7748==
==7748== HEAP SUMMARY:
==7748== in use at exit: 178,290 bytes in 1,090 blocks
==7748== total heap usage: 36,041 allocs, 34,951 frees, 5,692,166 bytes
allocated
==7748==
==7748== 5 bytes in 1 blocks are possibly lost in loss record 1 of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05882461: strdup (in /lib/libc-2.12.1.so)
==7748==    by 0x05b9098b: add_routing_table_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90a43: init_routing_table_names (in
/usr/lib/libnl.so.1.1)
==7748==
==7748== 5 bytes in 1 blocks are possibly lost in loss record 2 of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05882461: strdup (in /lib/libc-2.12.1.so)
==7748==    by 0x05b906eb: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b907b4: init_proto_names (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 6 bytes in 1 blocks are possibly lost in loss record 3 of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05882461: strdup (in /lib/libc-2.12.1.so)
==7748==    by 0x05b9098b: add_routing_table_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 7 bytes in 1 blocks are possibly lost in loss record 4 of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05882461: strdup (in /lib/libc-2.12.1.so)
==7748==    by 0x05b9098b: add_routing_table_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90a21: init_routing_table_names (in
/usr/lib/libnl.so.1.1)
==7748==
==7748== 7 bytes in 1 blocks are possibly lost in loss record 5 of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05882461: strdup (in /lib/libc-2.12.1.so)
==7748==    by 0x05b906eb: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90781: init_proto_names (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 7 bytes in 1 blocks are possibly lost in loss record 6 of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05882461: strdup (in /lib/libc-2.12.1.so)
==7748==    by 0x05b906eb: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b907a3: init_proto_names (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 7 bytes in 1 blocks are possibly lost in loss record 7 of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05882461: strdup (in /lib/libc-2.12.1.so)
==7748==    by 0x05b906eb: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 8 bytes in 1 blocks are possibly lost in loss record 8 of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05882461: strdup (in /lib/libc-2.12.1.so)
==7748==    by 0x05b9098b: add_routing_table_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90a32: init_routing_table_names (in
/usr/lib/libnl.so.1.1)
==7748==
==7748== 9 bytes in 1 blocks are possibly lost in loss record 9 of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05882461: strdup (in /lib/libc-2.12.1.so)
==7748==    by 0x05b906eb: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90792: init_proto_names (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 32 bytes in 1 blocks are possibly lost in loss record 10 of 22
==7748==    at 0x04c24879: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05b90977: add_routing_table_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90a21: init_routing_table_names (in
/usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 32 bytes in 1 blocks are possibly lost in loss record 11 of 22
==7748==    at 0x04c24879: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05b90977: add_routing_table_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90a32: init_routing_table_names (in
/usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 32 bytes in 1 blocks are possibly lost in loss record 12 of 22
==7748==    at 0x04c24879: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05b90977: add_routing_table_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90a43: init_routing_table_names (in
/usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 32 bytes in 1 blocks are possibly lost in loss record 13 of 22
==7748==    at 0x04c24879: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05b90977: add_routing_table_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b789ea: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 32 bytes in 1 blocks are possibly lost in loss record 14 of 22
==7748==    at 0x04c24879: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05b906d7: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90781: init_proto_names (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 32 bytes in 1 blocks are possibly lost in loss record 15 of 22
==7748==    at 0x04c24879: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05b906d7: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b90792: init_proto_names (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 32 bytes in 1 blocks are possibly lost in loss record 16 of 22
==7748==    at 0x04c24879: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05b906d7: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b907a3: init_proto_names (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 32 bytes in 1 blocks are possibly lost in loss record 17 of 22
==7748==    at 0x04c24879: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05b906d7: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b907b4: init_proto_names (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 32 bytes in 1 blocks are possibly lost in loss record 18 of 22
==7748==    at 0x04c24879: calloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x05b906d7: add_proto_name (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b9ebe5: ??? (in /usr/lib/libnl.so.1.1)
==7748==    by 0x05b789ea: ??? (in /usr/lib/libnl.so.1.1)
==7748==
==7748== 59,533 (28,560 direct, 30,973 indirect) bytes in 357 blocks are
definitely lost in loss record 21 of 22
==7748==    at 0x04c25c97: operator
==7748==    by 0x00401c40: main (main.cpp:44)
==7748==
==7748== 118,336 bytes in 357 blocks are definitely lost in loss record 22
of 22
==7748==    at 0x04c2619d: malloc (in
/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==7748==    by 0x04e43fba: install_bpf_program (in
/usr/lib/libpcap.so.1.1.1)
==7748==    by 0x00401e0a: main (main.cpp:73)
==7748==
==7748== LEAK SUMMARY:
==7748== definitely lost: 146,896 bytes in 714 blocks
==7748== indirectly lost: 30,973 bytes in 357 blocks
==7748== possibly lost: 349 bytes in 18 blocks
==7748== still reachable: 72 bytes in 1 blocks
==7748== suppressed: 0 bytes in 0 blocks
==7748== Reachable blocks (those to which a pointer was found) are not
shown.
==7748== To see them, rerun with: --leak-check=full --show-reachable=yes
==7748==
==7748== For counts of detected and suppressed errors, rerun with: -v
==7748== ERROR SUMMARY: 20 errors from 20 contexts (suppressed: 7 from 7)
==7748==



Thanks in advance,


-- 
Flavio Sales Truzzi

Engenharia Elétrica habilitação Computação e Sistemas Digitais
LARC - Laboratório de Arquitetura e Redes de Computadores
Escola Politécnica da USP
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: