Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 3be3776

Browse files
NoahStappblink1073
authored andcommitted
PYTHON-5571 - Fix memory leak when raising InvalidDocument with C extensions (mongodb#2573)
(cherry picked from commit 52400e1)
1 parent 23abc9f commit 3be3776

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

‎bson/_cbsonmodule.c‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,26 +1657,28 @@ void handle_invalid_doc_error(PyObject* dict) {
16571657
}
16581658

16591659
if (evalue && PyErr_GivenExceptionMatches(etype, InvalidDocument)) {
1660-
PyObject*msg = PyObject_Str(evalue);
1660+
msg = PyObject_Str(evalue);
16611661
if (msg) {
16621662
const char * msg_utf8 = PyUnicode_AsUTF8(msg);
16631663
if (msg_utf8 == NULL) {
16641664
goto cleanup;
16651665
}
1666-
PyObject*new_msg = PyUnicode_FromFormat("Invalid document: %s", msg_utf8);
1666+
new_msg = PyUnicode_FromFormat("Invalid document: %s", msg_utf8);
16671667
if (new_msg == NULL) {
16681668
goto cleanup;
16691669
}
16701670
// Add doc to the error instance as a property.
1671-
PyObject*new_evalue = PyObject_CallFunctionObjArgs(InvalidDocument, new_msg, dict, NULL);
1671+
new_evalue = PyObject_CallFunctionObjArgs(InvalidDocument, new_msg, dict, NULL);
16721672
Py_DECREF(evalue);
16731673
Py_DECREF(etype);
16741674
etype = InvalidDocument;
16751675
InvalidDocument = NULL;
16761676
if (new_evalue) {
16771677
evalue = new_evalue;
1678+
new_evalue = NULL;
16781679
} else {
16791680
evalue = msg;
1681+
msg = NULL;
16801682
}
16811683
}
16821684
PyErr_NormalizeException(&etype, &evalue, &etrace);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /