Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't leak objects in _pickle_27.c load_[short_]binbytes. #37

Merged
merged 1 commit into from
May 16, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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='[email protected]',
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