Skip to content

BUG: Reference leak in pandas/_libs/src/ujson/python/objToJSON.c #49222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
JelleZijlstra opened this issue Oct 21, 2022 · 3 comments · Fixed by #49466
Closed
3 tasks done

BUG: Reference leak in pandas/_libs/src/ujson/python/objToJSON.c #49222

JelleZijlstra opened this issue Oct 21, 2022 · 3 comments · Fixed by #49466
Labels
Bug IO JSON read_json, to_json, json_normalize Performance Memory or execution speed performance

Comments

@JelleZijlstra
Copy link

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

n/a

Issue Description

Various code starting at

calls PyObject_GetAttrString, but never DECREFs the values returned from the function. This means that these references are leaked, and the objects are never deallocated even if pandas is unimported.

I am happy to prepare a PR to fix this, but I'm not entirely sure what the code in question is even trying to do; it simply accesses these attributes and does nothing with the result.

Found via python/cpython#98253.

Expected Behavior

No memory leaks

Installed Versions

>>> pandas.show_versions()
/Library/Frameworks/Python.framework/Versions/3.11/lib/python3.11/site-packages/_distutils_hack/__init__.py:33: UserWarning: Setuptools is replacing distutils.
  warnings.warn("Setuptools is replacing distutils.")

INSTALLED VERSIONS
------------------
commit           : 91111fd99898d9dcaa6bf6bedb662db4108da6e6
python           : 3.11.0.candidate.2
python-bits      : 64
OS               : Darwin
OS-release       : 21.6.0
Version          : Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64
machine          : x86_64
processor        : i386
byteorder        : little
LC_ALL           : None
LANG             : en_US.UTF-8
LOCALE           : en_US.UTF-8

pandas           : 1.5.1
numpy            : 1.23.4
pytz             : 2022.5
dateutil         : 2.8.2
setuptools       : 63.2.0
pip              : 22.3
Cython           : 0.29.32
pytest           : None
hypothesis       : None
sphinx           : None
blosc            : None
feather          : None
xlsxwriter       : 3.0.3
lxml.etree       : 4.9.1
html5lib         : None
pymysql          : None
psycopg2         : None
jinja2           : 3.1.2
IPython          : 8.5.0
pandas_datareader: None
bs4              : None
bottleneck       : None
brotli           : None
fastparquet      : None
fsspec           : None
gcsfs            : None
matplotlib       : None
numba            : None
numexpr          : None
odfpy            : None
openpyxl         : None
pandas_gbq       : None
pyarrow          : None
pyreadstat       : None
pyxlsb           : None
s3fs             : None
scipy            : None
snappy           : None
sqlalchemy       : None
tables           : None
tabulate         : 0.8.10
xarray           : None
xlrd             : None
xlwt             : None
zstandard        : None
tzdata           : None
@JelleZijlstra JelleZijlstra added Bug Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 21, 2022
@jbrockmendel
Copy link
Member

cc @WillAyd

@mroeschke mroeschke added Performance Memory or execution speed performance IO JSON read_json, to_json, json_normalize and removed Needs Triage Issue that has not been reviewed by a pandas team member labels Oct 21, 2022
@WillAyd
Copy link
Member

WillAyd commented Oct 21, 2022

Yea this is created in an init for the module when it is instantiated. I think could use a cleanup function attached to the module if you'd like to add

@WillAyd
Copy link
Member

WillAyd commented Oct 21, 2022

The code is assigning to a static object that gets referenced throughout actual usage of the program. This is arguably bad design so could refactor if more ambitious, but no expectations (there's a lot of spaghetti code)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug IO JSON read_json, to_json, json_normalize Performance Memory or execution speed performance
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants