Repository: qpid-cpp Updated Branches: refs/heads/master f04bc169f -> f91a23c59
QPID-7702: Fix some minor memory leaks detected by Coverity scan Use SWIG_fail instead of returning on error. Avoid possible leaks during exception handling. Project: http://git-wip-us.apache.org/repos/asf/qpid-cpp/repo Commit: http://git-wip-us.apache.org/repos/asf/qpid-cpp/commit/f91a23c5 Tree: http://git-wip-us.apache.org/repos/asf/qpid-cpp/tree/f91a23c5 Diff: http://git-wip-us.apache.org/repos/asf/qpid-cpp/diff/f91a23c5 Branch: refs/heads/master Commit: f91a23c59e18fcdc1560687e14813346468fec3d Parents: f04bc16 Author: Kenneth Giusti <[email protected]> Authored: Mon Mar 13 15:07:25 2017 -0400 Committer: Kenneth Giusti <[email protected]> Committed: Thu Mar 23 15:53:47 2017 -0400 ---------------------------------------------------------------------- bindings/qmf2/python/cqmf2.i | 10 +++++++--- bindings/qpid/python/qpid_messaging.i | 10 +++++++--- 2 files changed, 14 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/f91a23c5/bindings/qmf2/python/cqmf2.i ---------------------------------------------------------------------- diff --git a/bindings/qmf2/python/cqmf2.i b/bindings/qmf2/python/cqmf2.i index 6b5326f..b8d25b7 100644 --- a/bindings/qmf2/python/cqmf2.i +++ b/bindings/qmf2/python/cqmf2.i @@ -23,17 +23,21 @@ /* Define the general-purpose exception handling */ %exception { + bool failed = true; std::string error; Py_BEGIN_ALLOW_THREADS; try { $action + failed = false; } catch (qpid::types::Exception& ex) { error = ex.what(); } Py_END_ALLOW_THREADS; - if (!error.empty()) { - PyErr_SetString(PyExc_RuntimeError, error.c_str()); - return NULL; + if (failed) { + if (!error.empty()) { + PyErr_SetString(PyExc_RuntimeError, error.c_str()); + } + SWIG_fail; } } http://git-wip-us.apache.org/repos/asf/qpid-cpp/blob/f91a23c5/bindings/qpid/python/qpid_messaging.i ---------------------------------------------------------------------- diff --git a/bindings/qpid/python/qpid_messaging.i b/bindings/qpid/python/qpid_messaging.i index 688b7ea..aee9930 100644 --- a/bindings/qpid/python/qpid_messaging.i +++ b/bindings/qpid/python/qpid_messaging.i @@ -101,10 +101,12 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError) /* Define the general-purpose exception handling */ %exception { PyObject * pExceptionType = NULL; + bool failed = true; std::string error; Py_BEGIN_ALLOW_THREADS; try { $action + failed = false; } /* Catch and translate exceptions. */ TRANSLATE_EXCEPTION(qpid::messaging::NoMessageAvailable, Empty) @@ -132,9 +134,11 @@ QPID_EXCEPTION(UnauthorizedAccess, SessionError) TRANSLATE_EXCEPTION(qpid::messaging::MessagingException, MessagingError) TRANSLATE_EXCEPTION(qpid::types::Exception, PyExc_RuntimeError) Py_END_ALLOW_THREADS; - if (!error.empty()) { - PyErr_SetString(pExceptionType, error.c_str()); - return NULL; + if (failed) { + if (!error.empty()) { + PyErr_SetString(pExceptionType, error.c_str()); + } + SWIG_fail; } } --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
