Can't delete contained pointers.

21 views
Skip to first unread message

Leonardo da Silva

unread,
Feb 17, 2015, 1:01:48 PM2/17/15
to libcr...@googlegroups.com
Hi there,

I've found some odd behavior, taken the sample code below:

   std::vector<Packet*> test_vec;
    while(packet = pcap_next(pcap_handle, &header)) {
        Packet* pkt;
      
        // libcrafter create packet starting with L2.
        pkt = new Packet(packet, header.len, Ethernet::PROTO);
       
        test_vec.push_back(pkt);
    }
   
    std::vector<Packet*>::iterator it;
    for(it = test_vec.begin(); it != test_vec.end(); ++it ) {
       /* RIGHT HERE MEMORY FROM THE PACKET IS NOT DEALLOCADED! */
        delete (*it);
    }

I'm my missing somethin obviuous?

Thanks in advance,
Leo

Esteban Pellegrino

unread,
Feb 18, 2015, 11:54:22 AM2/18/15
to libcr...@googlegroups.com
what do you mean  by "not deallocated" ? because the RAM consumption of the process is not decreasing? that could be related to the memory management of the std c++ library which is not returning the heap allocated memory to the system. but if you keep allocating other objects the heap memory will be reused.

can you run the code using valgrind? or post a full working code snippet of the relevant part of libcrafter?

 thanks

--
You received this message because you are subscribed to the Google Groups "libcrafter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libcrafter+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Esteban Pellegrino | Software Developer
Twitter | Zimperium.com


Leonardo da Silva

unread,
Feb 20, 2015, 7:57:20 PM2/20/15
to libcr...@googlegroups.com
Hi Esteban,

It's really the case where the std c++/operating system reusing the heap memory. I did check it will valgrind and there was no leaks. I have changed my solution to parse the packet using libcrafter and then saving raw data in some other structure, This way i have solved the memory footprint problem. Lets keep in touch i would like to be a contributor to the project, my email is independent.scientist[at]gmail.com.

Cheers,
Reply all
Reply to author
Forward
0 new messages