-
-
Notifications
You must be signed in to change notification settings - Fork 34.5k
gh-146152: Fix memory leak in _json encoder error paths #146164
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
Changes from 3 commits
0597100
9ec9348
cd9cc6f
5428b5e
b68b52b
cafe9ba
a4be61f
f7bdb6f
f09ce9a
5359ecd
753a88e
6498f26
6b69fea
81332c7
a9c895e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| Fix a memory leak in the :mod:`json` module when encoding objects with a | ||
|
okiemute04 marked this conversation as resolved.
Outdated
|
||
| custom ``default()`` function that raises an exception, when a recursion | ||
| error occurs, or when nested encoding fails. | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -1632,8 +1632,12 @@ encoder_listencode_obj(PyEncoderObject *s, PyUnicodeWriter *writer, | |||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if (_Py_EnterRecursiveCall(" while encoding a JSON object")) { | ||||||||||||||||||||||||||
| if (ident != NULL) { | ||||||||||||||||||||||||||
| PyDict_DelItem(s->markers, ident); | ||||||||||||||||||||||||||
|
okiemute04 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||
| Py_XDECREF(ident); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+1635
to
+1637
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Actually since we are anyway falling through the return -1 case we can simplify this as follows. Then keep the XDECREF for indent. However explicitly suppress the error code of DelItem. |
||||||||||||||||||||||||||
| Py_DECREF(newobj); | ||||||||||||||||||||||||||
| Py_XDECREF(ident); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
okiemute04 marked this conversation as resolved.
Outdated
|
||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| rv = encoder_listencode_obj(s, writer, newobj, indent_level, indent_cache); | ||||||||||||||||||||||||||
|
|
@@ -1642,6 +1646,7 @@ encoder_listencode_obj(PyEncoderObject *s, PyUnicodeWriter *writer, | |||||||||||||||||||||||||
| Py_DECREF(newobj); | ||||||||||||||||||||||||||
| if (rv) { | ||||||||||||||||||||||||||
| _PyErr_FormatNote("when serializing %T object", obj); | ||||||||||||||||||||||||||
|
okiemute04 marked this conversation as resolved.
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please revert this
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. okay
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Revert cosmetic changes. Nothing was properly reverted. |
||||||||||||||||||||||||||
| Py_XDECREF(ident); | ||||||||||||||||||||||||||
| return -1; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.