From 6c90315f6f371c1f30b2c2ba43519ddb1a64502b Mon Sep 17 00:00:00 2001 From: Omar Sandoval Date: Tue, 16 Aug 2022 17:35:36 -0700 Subject: [PATCH] python: fix FaultError reference leak PyErr_SetObject() takes a reference on the exception value, so we need to drop the reference we got when we created the value. Issue #196 ran into this by reading tons of unmapped addresses. Fixes: 80fef04c704d ("Add address attribute to FaultError exception") Signed-off-by: Omar Sandoval --- libdrgn/python/error.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libdrgn/python/error.c b/libdrgn/python/error.c index 3a063405..d04e8d2d 100644 --- a/libdrgn/python/error.c +++ b/libdrgn/python/error.c @@ -161,8 +161,10 @@ DRGNPY_PUBLIC void *set_drgn_error(struct drgn_error *err) exc = PyObject_CallFunction((PyObject *)&FaultError_type, "sK", err->message, err->address); - if (exc) + if (exc) { PyErr_SetObject((PyObject *)&FaultError_type, exc); + Py_DECREF(exc); + } break; } case DRGN_ERROR_TYPE: