From: Mike Bayer Date: Fri, 22 Apr 2022 14:27:38 +0000 (-0400) Subject: fix memory leak in resultproxy.c X-Git-Tag: rel_1_4_36~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3daa7c905cf03223655db10b951c5c3511b156df;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git fix memory leak in resultproxy.c the error raised for non-existent attribute didn't free the "name" string, causing a leak. Fixed a memory leak in the C extensions which could occur when calling upon named members of :class:`.Row` when the member does not exist under Python 3; in particular this could occur during numpy transformations when it attempts to call members such as ``.__array__``, but the issue was surrounding any ``AttributeError`` thrown by the :class:`.Row` object. This issue does not apply to version 2.0 which has already transitioned to Cython. Thanks much to Sebastian Berg for identifying the problem. Fixes: #7875 Change-Id: I444026a877ea1473a5ffac592c7f36ed6f4b563e --- diff --git a/doc/build/changelog/unreleased_14/7875.rst b/doc/build/changelog/unreleased_14/7875.rst new file mode 100644 index 0000000000..a56fa80106 --- /dev/null +++ b/doc/build/changelog/unreleased_14/7875.rst @@ -0,0 +1,12 @@ +.. change:: + :tags: bug, engine + :tickets: 7875 + + Fixed a memory leak in the C extensions which could occur when calling upon + named members of :class:`.Row` when the member does not exist under Python + 3; in particular this could occur during numpy transformations when it + attempts to call members such as ``.__array__``, but the issue was + surrounding any ``AttributeError`` thrown by the :class:`.Row` object. This + issue does not apply to version 2.0 which has already transitioned to + Cython. Thanks much to Sebastian Berg for identifying the problem. + diff --git a/lib/sqlalchemy/cextension/resultproxy.c b/lib/sqlalchemy/cextension/resultproxy.c index c071ff3173..785ad7e807 100644 --- a/lib/sqlalchemy/cextension/resultproxy.c +++ b/lib/sqlalchemy/cextension/resultproxy.c @@ -541,6 +541,7 @@ BaseRow_getattro(BaseRow *self, PyObject *name) "Could not locate column in row for column '%.200s'", PyBytes_AS_STRING(err_bytes) ); + Py_DECREF(err_bytes); #else PyErr_Format( PyExc_AttributeError,