summaryrefslogtreecommitdiff
path: root/msgpack/_packer.pyx
diff options
context:
space:
mode:
authorINADA Naoki <methane@users.noreply.github.com>2018-01-11 23:50:41 +0900
committerGitHub <noreply@github.com>2018-01-11 23:50:41 +0900
commitd9ec8fc905fc9ed37c86700f794adeb883b4f5ea (patch)
treec6e04f096bf0f6adc0c8632a98d0a05019fc7559 /msgpack/_packer.pyx
parent60ef3879d792ec92480cf9d6d610951657c2e8c7 (diff)
downloadmsgpack-python-d9ec8fc905fc9ed37c86700f794adeb883b4f5ea.tar.gz
Packer.pack() reset buffer on exception (#274)
fixes #210
Diffstat (limited to 'msgpack/_packer.pyx')
-rw-r--r--msgpack/_packer.pyx12
1 files changed, 7 insertions, 5 deletions
diff --git a/msgpack/_packer.pyx b/msgpack/_packer.pyx
index a4913ab..35e5a9d 100644
--- a/msgpack/_packer.pyx
+++ b/msgpack/_packer.pyx
@@ -289,11 +289,13 @@ cdef class Packer(object):
cpdef pack(self, object obj):
cdef int ret
- ret = self._pack(obj, DEFAULT_RECURSE_LIMIT)
- if ret == -1:
- raise MemoryError
- elif ret: # should not happen.
- raise TypeError
+ try:
+ ret = self._pack(obj, DEFAULT_RECURSE_LIMIT)
+ except:
+ self.pk.length = 0
+ raise
+ if ret: # should not happen.
+ raise RuntimeError("internal error")
if self.autoreset:
buf = PyBytes_FromStringAndSize(self.pk.buf, self.pk.length)
self.pk.length = 0