Fixed a handful of reference leaks found in a debug build of Python (#484)
* Fixed some reference leaks.
* Fixed a few reference leaks.
* Fixed a few more memory errors.
* Fixed a few more reference leaks.
* Revert minimal_test.py.
* Re-enable limited API.
* Removed some debugging and spurious changes.
* Addressed PR comments.
diff --git a/python/descriptor_pool.c b/python/descriptor_pool.c
index 95e14fe..1b0d325 100644
--- a/python/descriptor_pool.c
+++ b/python/descriptor_pool.c
@@ -135,7 +135,10 @@
return false;
}
if (proto == Py_None) return true;
- return PyUpb_DescriptorPool_DoAdd((PyObject*)self, proto) != NULL;
+ PyObject* ret = PyUpb_DescriptorPool_DoAdd((PyObject*)self, proto);
+ bool ok = ret != NULL;
+ Py_XDECREF(ret);
+ return ok;
}
static bool PyUpb_DescriptorPool_TryLoadSymbol(PyUpb_DescriptorPool* self,
@@ -246,13 +249,14 @@
static PyObject* PyUpb_DescriptorPool_DoAdd(PyObject* _self,
PyObject* file_desc) {
- PyObject* subargs = PyTuple_New(0);
if (!PyUpb_CMessage_Check(file_desc)) return NULL;
const upb_MessageDef* m = PyUpb_CMessage_GetMsgdef(file_desc);
const char* file_proto_name = "google.protobuf.FileDescriptorProto";
if (strcmp(upb_MessageDef_FullName(m), file_proto_name) != 0) {
return PyErr_Format(PyExc_TypeError, "Can only add FileDescriptorProto");
}
+ PyObject* subargs = PyTuple_New(0);
+ if (!subargs) return NULL;
PyObject* serialized =
PyUpb_CMessage_SerializeToString(file_desc, subargs, NULL);
Py_DECREF(subargs);