Skip to content

Commit

Permalink
pythongh-125196: PyUnicodeWriter_Discard(NULL) does nothing
Browse files Browse the repository at this point in the history
  • Loading branch information
vstinner committed Oct 9, 2024
1 parent 52f70da commit 5e51ebf
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
2 changes: 2 additions & 0 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1600,6 +1600,8 @@ object.
Discard the internal Unicode buffer and destroy the writer instance.
Do nothing if *writer* is ``NULL``.
.. c:function:: int PyUnicodeWriter_WriteChar(PyUnicodeWriter *writer, Py_UCS4 ch)
Write the single Unicode character *ch* into *writer*.
Expand Down
4 changes: 1 addition & 3 deletions Objects/listobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -563,9 +563,7 @@ list_repr_impl(PyListObject *v)
return PyUnicodeWriter_Finish(writer);

error:
if (writer != NULL) {
PyUnicodeWriter_Discard(writer);
}
PyUnicodeWriter_Discard(writer);
Py_ReprLeave((PyObject *)v);
return NULL;
}
Expand Down
3 changes: 3 additions & 0 deletions Objects/unicodeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -13455,6 +13455,9 @@ PyUnicodeWriter_Create(Py_ssize_t length)

void PyUnicodeWriter_Discard(PyUnicodeWriter *writer)
{
if (writer == NULL) {
return;
}
_PyUnicodeWriter_Dealloc((_PyUnicodeWriter*)writer);
PyMem_Free(writer);
}
Expand Down

0 comments on commit 5e51ebf

Please sign in to comment.