Skip to content

Python: reference leak in pyopencv_to modules/python/src2/cv2_convert.cpp #28046

@mayeut

Description

@mayeut

System Information

OpenCV python version: 4.11.0.86
Operating System / Platform: Oracle Linux 8 x86_64
Python version: 3.14.0

Detailed description

The call to PyOS_FSPath returns a new strong reference but Py_XDECREF is never called on that returned value.

obj = PyOS_FSPath(obj);

Steps to reproduce

build python with --with-address-sanitizer & --without-pymalloc to get a working leak sanitiser.

from pathlib import Path
import cv2

cv2.imread(Path("image.jpg"))

LeakSanitizer will report a leak for a memory block allocated by a call to PyOS_FSPath.
Running with a string rather than a Path will report the leak coming from elsewhere (as PyOS_FSPath is just a ref count increment in this case)

Any function argument annotated with CV_WRAP_FILE_PATH will leak, cv2.imread is just one of them.

Issue submission checklist

  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues, forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files (videos, images, onnx, etc)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions