Skip to content

bpf-map fd leak #806

@goldshtn

Description

@goldshtn

The following program leaks a bpf-map file descriptor every second (verify with lsof | grep bpf-map). I've added None assignments and even a gc.collect call to rule out any possibility of some object not getting reclaimed because of the Python runtime. It looks like we genuinely have a leak somewhere whereby the map fd is not getting closed.

#!/usr/bin/env python

from bcc import BPF
from time import sleep
import gc

prog = """
BPF_HASH(map);

int probe(struct pt_regs *ctx) {
    return 0;
}
"""

while True:
    bpf = BPF(text=prog)
    bpf.attach_kprobe(event="__kmalloc", fn_name="probe")
    m = bpf["map"]
    m.items()
    bpf.cleanup()
    m = None
    bpf = None
    gc.collect()
    sleep(1)

/cc @4ast @drzaeus77

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions