You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@thrift.apache.org by ns...@apache.org on 2016/03/29 19:48:42 UTC

[8/9] thrift git commit: THRIFT-3765 fix memory leak in python compact protocol extension

THRIFT-3765 fix memory leak in python compact protocol extension

This closes #970


Project: http://git-wip-us.apache.org/repos/asf/thrift/repo
Commit: http://git-wip-us.apache.org/repos/asf/thrift/commit/6657b833
Tree: http://git-wip-us.apache.org/repos/asf/thrift/tree/6657b833
Diff: http://git-wip-us.apache.org/repos/asf/thrift/diff/6657b833

Branch: refs/heads/master
Commit: 6657b8337d1aedfd2aed22a8cdcf4b96965ece26
Parents: 4ab9a88
Author: Chandler May <cj...@gmail.com>
Authored: Sun Mar 27 22:47:06 2016 -0400
Committer: Nobuaki Sukegawa <ns...@apache.org>
Committed: Tue Mar 29 12:03:34 2016 +0900

----------------------------------------------------------------------
 lib/py/src/ext/protocol.tcc | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/thrift/blob/6657b833/lib/py/src/ext/protocol.tcc
----------------------------------------------------------------------
diff --git a/lib/py/src/ext/protocol.tcc b/lib/py/src/ext/protocol.tcc
index 2f0d083..6e978d7 100644
--- a/lib/py/src/ext/protocol.tcc
+++ b/lib/py/src/ext/protocol.tcc
@@ -418,19 +418,24 @@ bool ProtocolBase<Impl>::encodeValue(PyObject* value, TType type, PyObject* type
   }
 
   case T_STRING: {
+    ScopedPyObject nval;
+
     if (PyUnicode_Check(value)) {
-      value = PyUnicode_AsUTF8String(value);
-      if (!value) {
+      nval.reset(PyUnicode_AsUTF8String(value));
+      if (!nval) {
         return false;
       }
+    } else {
+      Py_INCREF(value);
+      nval.reset(value);
     }
 
-    Py_ssize_t len = PyBytes_Size(value);
+    Py_ssize_t len = PyBytes_Size(nval.get());
     if (!detail::check_ssize_t_32(len)) {
       return false;
     }
 
-    impl()->writeString(value, static_cast<int32_t>(len));
+    impl()->writeString(nval.get(), static_cast<int32_t>(len));
     return true;
   }