Skip to content

Commit 025b7a4

Browse files
committed
BUG#35141645: Memory leak in the mysqlx C extension
Change-Id: I9469eb7cfd48007cfbe62ee8ddb868255cfa8839
1 parent 7cb62f9 commit 025b7a4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ v8.2.0
1919
- BUG#35547876: C/Python 8.1.0 type check build fails in the pb2 branch
2020
- BUG#35544123: Kerberos unit tests configuration is outdated
2121
- BUG#35503506: Query on information_schema.columns returns bytes
22+
- BUG#35141645: Memory leak in the mysqlx C extension
2223

2324
v8.1.0
2425
======

src/mysqlxpb/mysqlxpb.cc

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,12 +625,16 @@ static void PythonAddList(PyObject* list, int index,
625625

626626
static PyObject* CreateMessage(const google::protobuf::Message& message) {
627627
PyObject* dict = PyDict_New();
628+
PyObject* desc_full_name;
628629
const google::protobuf::Descriptor* descriptor = message.GetDescriptor();
629630
const google::protobuf::Reflection* reflection = message.GetReflection();
630631

631632
try {
632-
PyDict_SetItemString(dict, kMessageTypeKey,
633-
PyString_FromString(descriptor->full_name().c_str()));
633+
// PyString_FromString which relies on PyUnicode_FromString returns a new reference
634+
desc_full_name = PyString_FromString(descriptor->full_name().c_str());
635+
636+
// PyDict_SetItemString does not steal a reference to val (last argument).
637+
PyDict_SetItemString(dict, kMessageTypeKey, desc_full_name);
634638

635639
for (int idx = 0; idx < descriptor->field_count(); ++idx) {
636640
const google::protobuf::FieldDescriptor* field = descriptor->field(idx);
@@ -658,10 +662,12 @@ static PyObject* CreateMessage(const google::protobuf::Message& message) {
658662
}
659663
}
660664
} catch(std::exception& e) {
665+
Py_DECREF(desc_full_name);
661666
Py_CLEAR(dict);
662667
dict = NULL;
663668
PyErr_SetString(PyExc_RuntimeError, e.what());
664669
}
670+
Py_DECREF(desc_full_name);
665671
return dict;
666672
}
667673

0 commit comments

Comments
 (0)