scapy icon indicating copy to clipboard operation
scapy copied to clipboard

memory leak when creating AsyncSniffer repeatedly

Open bingwang-ms opened this issue 10 months ago • 0 comments

Brief description

Memory is not freed when creating AsyncSniffer repeatedly.

Test code

from scapy.all import *
import time


def process_packet(packet):
    pass

def start_sniff():
    ifaces = ["PortChannel102", "PortChannel103", "PortChannel104", "PortChannel105", "PortChannel106", "PortChannel107", "PortChannel108", "PortChannel109"]
    sniffstring = "udp and (dst host " + str("10.1.0.32") + " or dst host " + "fc00:1::32" +  ") and dst port " + str(65330)
    sniffer = AsyncSniffer(iface=ifaces, filter=sniffstring, prn=process_packet, store=False)
    sniffer.start()
    RETRY = 30
    while RETRY >= 0 and not hasattr(sniffer, 'stop_cb'):
        time.sleep(0.1)
        RETRY -= 1
    print("Sniff started")
    try:
        sniffer.stop()
    except:
        pass
    else:
        print("Sniff stopped")

def main():
    while True:
        start_sniff()
        time.sleep(1)

if __name__ == "__main__":
    main()

Scapy version

2.4.5

Python version

3.9.2

Operating system

Debian GNU/Linux 11 (bullseye)

Additional environment information

No response

How to reproduce

Run the script and monitor the memory usage

Actual result

No response

Expected result

No response

Related resources

No response

bingwang-ms avatar Mar 19 '25 00:03 bingwang-ms