diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-11 22:01:40 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2002-07-11 22:01:40 (GMT) |
commit | 0e1f7a82e9024555a57eb2371aeeb25d5bc15e6a (patch) | |
tree | 8f72db7a5b7c192dbbf803774d52a2d3df4de5da /Modules | |
parent | f2a0473350d91065cb1ac14ca4b55d56eea1ed38 (diff) | |
download | cpython-0e1f7a82e9024555a57eb2371aeeb25d5bc15e6a.zip cpython-0e1f7a82e9024555a57eb2371aeeb25d5bc15e6a.tar.gz cpython-0e1f7a82e9024555a57eb2371aeeb25d5bc15e6a.tar.bz2 |
Do more robust test of whether global objects are accessible.
PyImport_ImportModule() is not guaranteed to return a module object.
When another type of object was returned, the PyModule_GetDict() call
return NULL and the subsequent GetItem() seg faulted.
Bug fix candidate.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/cPickle.c | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/Modules/cPickle.c b/Modules/cPickle.c index 2484365..84c1d4f 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -1719,10 +1719,7 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) "OSS", args, module, global_name); goto finally; } - /* borrowed ref */ - moddict = PyModule_GetDict(mod); - /* borrowed ref */ - klass = PyDict_GetItemString(moddict, name_str); + klass = PyObject_GetAttrString(mod, name_str); if (klass == NULL) { cPickle_ErrFormat(PicklingError, "Can't pickle %s: it's not found as %s.%s", @@ -1730,11 +1727,13 @@ save_global(Picklerobject *self, PyObject *args, PyObject *name) goto finally; } if (klass != args) { + Py_DECREF(klass); cPickle_ErrFormat(PicklingError, "Can't pickle %s: it's not the same object as %s.%s", "OSS", args, module, global_name); goto finally; } + Py_DECREF(klass); if ((*self->write_func)(self, &global, 1) < 0) goto finally; |