Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 83addc7

Browse files
committed
Charles Waldman writes:
""" Problem description: Run the following script: import test.test_cpickle for x in xrange(1000000): reload(test.test_cpickle) Watch Python's memory use go up up and away! In the course of debugging this I also saw that cPickle is inconsistent with pickle - if you attempt a pickle.load or pickle.dump on a closed file, you get a ValueError, whereas the corresponding cPickle operations give an IOError. Since cPickle is advertised as being compatible with pickle, I changed these exceptions to match. """
1 parent 2dd8ddd commit 83addc7

1 file changed

Lines changed: 11 additions & 14 deletions

File tree

Modules/cPickle.c

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2151,19 +2151,18 @@ newPicklerobject(PyObject *file, int bin) {
21512151
Py_INCREF(file);
21522152
else
21532153
file=Pdata_New();
2154+
2155+
UNLESS (self->file = file)
2156+
goto err;
21542157

2155-
self->file = file;
2156-
2157-
UNLESS (self->memo = PyDict_New()) {
2158-
Py_XDECREF((PyObject *)self);
2159-
return NULL;
2160-
}
2158+
UNLESS (self->memo = PyDict_New())
2159+
goto err;
21612160

21622161
if (PyFile_Check(file)) {
21632162
self->fp = PyFile_AsFile(file);
21642163
if (self->fp == NULL) {
2165-
PyErr_SetString(PyExc_IOError, "output file closed");
2166-
return NULL;
2164+
PyErr_SetString(PyExc_ValueError, "I/O operation on closed file");
2165+
goto err;
21672166
}
21682167
self->write_func = write_file;
21692168
}
@@ -4054,10 +4053,8 @@ newUnpicklerobject(PyObject *f) {
40544053
self->safe_constructors = NULL;
40554054
self->find_class = NULL;
40564055

4057-
UNLESS (self->memo = PyDict_New()) {
4058-
Py_XDECREF((PyObject *)self);
4059-
return NULL;
4060-
}
4056+
UNLESS (self->memo = PyDict_New())
4057+
goto err;
40614058

40624059
Py_INCREF(f);
40634060
self->file = f;
@@ -4066,8 +4063,8 @@ newUnpicklerobject(PyObject *f) {
40664063
if (PyFile_Check(f)) {
40674064
self->fp = PyFile_AsFile(f);
40684065
if (self->fp == NULL) {
4069-
PyErr_SetString(PyExc_IOError, "input file closed");
4070-
return NULL;
4066+
PyErr_SetString(PyExc_ValueError, "I/O operation on closed file");
4067+
goto err;
40714068
}
40724069
self->read_func = read_file;
40734070
self->readline_func = readline_file;

0 commit comments

Comments
 (0)