Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Leak in PcapLiveDeviceList #1685

Closed
Yangc6 opened this issue Jan 8, 2025 · 8 comments
Closed

Memory Leak in PcapLiveDeviceList #1685

Yangc6 opened this issue Jan 8, 2025 · 8 comments
Labels

Comments

@Yangc6
Copy link

Yangc6 commented Jan 8, 2025

Bug description

Description

Build Tutorial-LiveTraffic example
Run with Valgrind:
sudo valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./Tutorial-LiveTraffic。Memory leak detected during network device enumeration in the PcapLiveDeviceList 。

Environment

  • PcapPlusPlus version: 24.09
  • libpcap version: 1.10.5
  • OS: Linux
  • Compiler: GCC
  • Analysis Tool: Valgrind 3.13.0

Call Stack

main()
-> PcapLiveDeviceList::PcapLiveDeviceList()
-> PcapLiveDeviceList::fetchAllLocalDevices()
-> pcpp::internal::getAllLocalPcapDevices()
-> pcap_findalldevs()


### PcapPlusPlus versions tested on

PcapPlusPlus master branch, Other (specify in the next question)

### Other PcapPlusPlus version (if applicable)

_No response_

### Operating systems tested on

Linux

### Other operation systems (if applicable)

_No response_

### Compiler version

gcc (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0

### Packet capture backend (if applicable)

libpcap
@Yangc6 Yangc6 added the bug label Jan 8, 2025
@seladb
Copy link
Owner

seladb commented Jan 10, 2025

@Dimi1010 can you take a look? You updated this code recently I believe...

@Yangc6
Copy link
Author

Yangc6 commented Jan 10, 2025

@seladb I found that using pcpp::P capLiveDeviceList::getInstance() has memory leaks. I used the same environment to test Tutorial-LiveTraffic in v23.09, and some other examples that use pcpp::P capLiveDeviceList::getInstance() also have memory leaks. I'm not sure if it's an issue with libpcap or this library.

@seladb
Copy link
Owner

seladb commented Jan 10, 2025

@seladb I found that using pcpp::P capLiveDeviceList::getInstance() has memory leaks. I used the same environment to test Tutorial-LiveTraffic in v23.09, and some other examples that use pcpp::P capLiveDeviceList::getInstance() also have memory leaks. I'm not sure if it's an issue with libpcap or this library.

@Yangc6 If the memory leak is inside pcap_findalldevs, then it's libpcap and there's not much we can do with it... Can you confirm it's in pcap_findalldevs?

@Yangc6
Copy link
Author

Yangc6 commented Jan 10, 2025

@seladb
test
I tested the pcap_findalldevs and found it fine.

@Yangc6
Copy link
Author

Yangc6 commented Jan 10, 2025

This is a screenshot of testing Tutorial-LiveTraffic in v23.09.
test1

@Dimi1010
Copy link
Collaborator

I am not showing any leaks. :/

PcapPlusPlus Version: master branch head (ab755348711dfb94fa0780c5aa71a8e6e614d132)
OS: Ubuntu 22.04 under WSL2
Libpcap version: 1.10.1
Compiler: GCC
Analysis: Valgrind 3.18.1

~/.vs/PcapPlusPlus/out/build/linux/tutorials_bin/Debug$ sudo valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./Tutorial-LiveTraffic
==2682== Memcheck, a memory error detector
==2682== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==2682== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==2682== Command: ./Tutorial-LiveTraffic
==2682==
Interface info:
   Interface name:        eth0
   Interface description:
   MAC address:           00:15:5d:68:69:28
   Default gateway:       172.28.160.1
   Interface MTU:         1500

Starting async capture...
Results:
Ethernet packet count: 0
IPv4 packet count:     0
IPv6 packet count:     0
TCP packet count:      0
UDP packet count:      0
DNS packet count:      0
HTTP packet count:     0
SSL packet count:      0

Starting capture with packet vector...
Results:
Ethernet packet count: 2
IPv4 packet count:     2
IPv6 packet count:     0
TCP packet count:      0
UDP packet count:      2
DNS packet count:      0
HTTP packet count:     0
SSL packet count:      0

Starting capture in blocking mode...
Results:
Ethernet packet count: 0
IPv4 packet count:     0
IPv6 packet count:     0
TCP packet count:      0
UDP packet count:      0
DNS packet count:      0
HTTP packet count:     0
SSL packet count:      0

Sending 2 packets one by one...
2 packets sent

Sending 2 packets...
2 packets sent

Starting packet capture with a filter in place...
Results:
Ethernet packet count: 0
IPv4 packet count:     0
IPv6 packet count:     0
TCP packet count:      0
==2682== HEAP SUMMARY:
==2682==     in use at exit: 0 bytes in 0 blocks
==2682==   total heap usage: 2,646 allocs, 2,646 frees, 375,878 bytes allocated
==2682==
==2682== All heap blocks were freed -- no leaks are possible
==2682==
==2682== For lists of detected and suppressed errors, rerun with: -s
==2682== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@Dimi1010
Copy link
Collaborator

Same with v23.09.

PcapPlusPlus Version: v23.09
OS: Ubuntu 22.04 under WSL2
Libpcap version: 1.10.1
Compiler: GCC
Analysis: Valgrind 3.18.1

~/.vs/PcapPlusPlus/out/build/linux/tutorials_bin/Debug$ sudo valgrind --leak-check=full --show-leak-kinds=all --track-origins=yes ./Tutorial-LiveTraffic
==3475== Memcheck, a memory error detector
==3475== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==3475== Using Valgrind-3.18.1 and LibVEX; rerun with -h for copyright info
==3475== Command: ./Tutorial-LiveTraffic
==3475==
Interface info:
   Interface name:        eth0
   Interface description:
   MAC address:           00:15:5d:68:69:28
   Default gateway:       172.28.160.1
   Interface MTU:         1500

Starting async capture...
Results:
Ethernet packet count: 6
IPv4 packet count:     2
IPv6 packet count:     0
TCP packet count:      0
UDP packet count:      2
DNS packet count:      0
HTTP packet count:     0
SSL packet count:      0

Starting capture with packet vector...
Results:
Ethernet packet count: 0
IPv4 packet count:     0
IPv6 packet count:     0
TCP packet count:      0
UDP packet count:      0
DNS packet count:      0
HTTP packet count:     0
SSL packet count:      0

Starting capture in blocking mode...
Results:
Ethernet packet count: 0
IPv4 packet count:     0
IPv6 packet count:     0
TCP packet count:      0
UDP packet count:      0
DNS packet count:      0
HTTP packet count:     0
SSL packet count:      0

Sending 0 packets one by one...
0 packets sent

Sending 0 packets...
0 packets sent

Starting packet capture with a filter in place...
Results:
Ethernet packet count: 0
IPv4 packet count:     0
IPv6 packet count:     0
TCP packet count:      0
UDP packet count:      0
DNS packet count:      0
HTTP packet count:     0
SSL packet count:      0
==3475==
==3475== HEAP SUMMARY:
==3475==     in use at exit: 0 bytes in 0 blocks
==3475==   total heap usage: 2,648 allocs, 2,648 frees, 376,090 bytes allocated
==3475==
==3475== All heap blocks were freed -- no leaks are possible
==3475==
==3475== For lists of detected and suppressed errors, rerun with: -s
==3475== ERROR SUMMARY: 0 errors from 0 contexts (suppressed: 0 from 0)

@Yangc6
Copy link
Author

Yangc6 commented Jan 10, 2025

@Dimi1010
image
Thanks, this code I downloaded compiled out to have a memory leak. The latest version pulled with git is no problem.

@Yangc6 Yangc6 closed this as completed Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants