pyroute2 icon indicating copy to clipboard operation
pyroute2 copied to clipboard

NetlinkSocket file descriptors of pipes leakage

Open socketpair opened this issue 1 year ago • 17 comments

#!/usr/bin/python3

from pyroute2.ethtool import Ethtool  # pylint: disable=no-name-in-module,import-error
import os
import subprocess
import gc

def main():
    subprocess.check_call(['ls', '-l', f'/proc/{os.getpid()}/fd'])
    Ethtool()
    gc.collect()
    subprocess.check_call(['ls', '-l', f'/proc/{os.getpid()}/fd'])

if __name__ == '__main__':
    main()

shows:

# ./zzz.py 
итого 0
lrwx------ 1 root root 64 мар 14 19:09 0 -> /dev/pts/3
lrwx------ 1 root root 64 мар 14 19:09 1 -> /dev/pts/3
lrwx------ 1 root root 64 мар 14 19:09 2 -> /dev/pts/3
итого 0
lrwx------ 1 root root 64 мар 14 19:09 0 -> /dev/pts/3
lrwx------ 1 root root 64 мар 14 19:09 1 -> /dev/pts/3
lrwx------ 1 root root 64 мар 14 19:09 2 -> /dev/pts/3
lr-x------ 1 root root 64 мар 14 19:09 4 -> 'pipe:[1256640]'
l-wx------ 1 root root 64 мар 14 19:09 5 -> 'pipe:[1256640]'

as you can see, two pipes (fd 4 and 5) leaked.

socketpair avatar Mar 14 '23 14:03 socketpair