Commit 8a466fa
In encoder_encode_key_value(), key is a borrowed reference from
PyDict_Next(). If the default callback mutates or clears the dict,
key becomes a dangling pointer. The error path then calls
_PyErr_FormatNote("%R", key) on freed memory.
Fix by holding strong references to key and value unconditionally
during encoding, not just in the free-threading build.
Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
1 parent daa2578 commit 8a466fa
File tree
3 files changed
+29
-7
lines changed- Lib/test/test_json
- Misc/NEWS.d/next/Library
- Modules
3 files changed
+29
-7
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
80 | 103 | | |
81 | 104 | | |
82 | 105 | | |
| |||
Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1784 | 1784 | | |
1785 | 1785 | | |
1786 | 1786 | | |
1787 | | - | |
1788 | | - | |
| 1787 | + | |
| 1788 | + | |
| 1789 | + | |
| 1790 | + | |
1789 | 1791 | | |
1790 | 1792 | | |
1791 | | - | |
1792 | 1793 | | |
1793 | 1794 | | |
1794 | 1795 | | |
1795 | | - | |
1796 | 1796 | | |
1797 | 1797 | | |
1798 | | - | |
1799 | 1798 | | |
1800 | 1799 | | |
1801 | | - | |
1802 | 1800 | | |
1803 | 1801 | | |
1804 | | - | |
1805 | 1802 | | |
1806 | 1803 | | |
1807 | 1804 | | |
| |||
0 commit comments