Skip to content

run_api_command leaks file descriptors #224

@JacobTDC

Description

@JacobTDC

When using the C library calls, run_api_command appears to leak file descriptors. Multiple calls to run_api_command in the same process builds up UNIX-STREAM file descriptors (two per call, presumably the in and out descriptors for communicating with the Termux:API plugin).

The created sockets should be closed before returning.

Code to reproduce (via. Python):

import ctypes
import sys
from os import getpid
from signal import pause

run_api_command = ctypes.CDLL("libtermux-api.so").run_api_command
run_api_command.argtypes = [ ctypes.c_int, ctypes.POINTER(ctypes.c_char_p) ]
run_api_command.restype = ctypes.c_int

args = f"{sys.argv[0]} Usb -a list"
argb = args.encode('utf8').split(b' ')
argv = (ctypes.c_char_p * len(argb))(*argb)

run_api_command(len(argv), argv)
run_api_command(len(argv), argv)
run_api_command(len(argv), argv)

print(f"Process ID: {getpid()}")
pause()

Running lsof -p [pid] on the resulting pid will reveal the leaked file descriptors.

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