Skip to content

Commit

Permalink
Merge pull request #37 from zopefoundation/issue36
Browse files Browse the repository at this point in the history
Don't leak objects in _pickle_27.c load_[short_]binbytes.
  • Loading branch information
jamadden committed May 16, 2018
2 parents eaea833 + a03e2b2 commit eb5d343
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 8 deletions.
5 changes: 3 additions & 2 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
``zodbpickle`` Changelog
========================

1.1 (unreleased)
1.0.1 (unreleased)
----------------

- Nothing changed yet.
- Fix a memory leak in pickle protocol 3 under Python 2. See `issue 36
<https://github.com/zopefoundation/zodbpickle/issues/36>`_.


1.0 (2018-02-09)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@

setup(
name='zodbpickle',
version='1.1.dev0',
version='1.0.1.dev0',
description='Fork of Python 3 pickle module.',
author='Python and Zope Foundation',
author_email='zodb-dev@zope.org',
Expand Down
35 changes: 30 additions & 5 deletions src/zodbpickle/_pickle_27.c
Original file line number Diff line number Diff line change
Expand Up @@ -3900,12 +3900,24 @@ load_binbytes(Unpicklerobject *self)
return -1;

if (!( args = PyTuple_New(1) ))
return -1;
goto done;

if (!(PyTuple_SET_ITEM(args, 0, py_string)))
return -1;
/* practically speaking this macro cannot fail */
goto done;

if (!( py_binary = PyObject_CallObject(BinaryType, args)))
goto done;

done:
if (!args) {
/* The tuple steals the string reference,
* so we don't need to decref it if we have the tuple.
*/
Py_XDECREF(py_string);
}
Py_XDECREF(args);
if ( !py_binary )
return -1;

PDATA_PUSH(self->stack, py_binary, -1);
Expand All @@ -3929,15 +3941,28 @@ load_short_binbytes(Unpicklerobject *self)

if (self->read_func(self, &s, l) < 0) return -1;

if (!( py_string = PyString_FromStringAndSize(s, l))) return -1;
if (!( py_string = PyString_FromStringAndSize(s, l)))
return -1;

if (!( args = PyTuple_New(1) ))
return -1;
goto done;

if (!(PyTuple_SET_ITEM(args, 0, py_string)))
return -1;
/* practically speaking this macro cannot fail */
goto done;

if (!( py_binary = PyObject_CallObject(BinaryType, args)))
goto done;

done:
if (!args) {
/* The tuple steals the string reference,
* so we don't need to decref it if we have the tuple.
*/
Py_XDECREF(py_string);
}
Py_XDECREF(args);
if ( !py_binary )
return -1;

PDATA_PUSH(self->stack, py_binary, -1);
Expand Down

0 comments on commit eb5d343

Please sign in to comment.