Skip to content

[Bug]: double free when FT2Font constructor is interrupted by KeyboardInterrupt #21364

Closed
@anntzer

Description

@anntzer

Bug summary

Ctrl-C'ing during construction of the font cache can occasionally result in a double-free error.

Code for reproduction

rm ~/.cache/matplotlib/fontlist*.json; \python -c 'import matplotlib.pyplot; print("done")' & sleep 2 && pkill -INT python
You may have to run this a couple of times and/or adjust the sleep time to see the problem.

Actual outcome

Exception ignored in: <matplotlib.ft2font.FT2Font object at 0x7fb0e1a643a0>                                                                                                                         
Traceback (most recent call last):
  File "/home/antony/src/extern/matplotlib/lib/matplotlib/font_manager.py", line 1092, in addfont
    font = ft2font.FT2Font(path)
KeyboardInterrupt: 
free(): double free detected in tcache 2
Fatal Python error: Aborted

Thread 0x00007fb0e1a2b640 (most recent call first):
  File "/usr/lib/python3.9/threading.py", line 316 in wait
  File "/usr/lib/python3.9/threading.py", line 574 in wait
  File "/usr/lib/python3.9/threading.py", line 1284 in run
  File "/usr/lib/python3.9/threading.py", line 973 in _bootstrap_inner
  File "/usr/lib/python3.9/threading.py", line 930 in _bootstrap

Current thread 0x00007fb104faa740 (most recent call first):
  File ".../matplotlib/font_manager.py", line 1092 in addfont
  <elided>

Expected outcome

Just the KeyboardInterrupt.

Operating system

arch linux and fedora (edited: confirmed on fedora as well)

Matplotlib Version

3.5.0.dev2291+gc8a902d3f2

Matplotlib Backend

mplcairo

Python version

3.9

Jupyter version

no

Other libraries

No response

Installation

No response

Conda channel

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions