Fix bug [ 549731 ] Unicode encoders appears to leak references.

Python 2.2.1 bugfix candidate.
This commit is contained in:
Mark Hammond 2002-07-18 23:06:17 +00:00
parent 5a7ef7e2b5
commit e21262ca9e
1 changed files with 10 additions and 4 deletions

View File

@ -271,6 +271,7 @@ PyObject *PyCodec_Encoder(const char *encoding)
if (codecs == NULL) if (codecs == NULL)
goto onError; goto onError;
v = PyTuple_GET_ITEM(codecs,0); v = PyTuple_GET_ITEM(codecs,0);
Py_DECREF(codecs);
Py_INCREF(v); Py_INCREF(v);
return v; return v;
@ -287,6 +288,7 @@ PyObject *PyCodec_Decoder(const char *encoding)
if (codecs == NULL) if (codecs == NULL)
goto onError; goto onError;
v = PyTuple_GET_ITEM(codecs,1); v = PyTuple_GET_ITEM(codecs,1);
Py_DECREF(codecs);
Py_INCREF(v); Py_INCREF(v);
return v; return v;
@ -298,12 +300,14 @@ PyObject *PyCodec_StreamReader(const char *encoding,
PyObject *stream, PyObject *stream,
const char *errors) const char *errors)
{ {
PyObject *codecs; PyObject *codecs, *ret;
codecs = _PyCodec_Lookup(encoding); codecs = _PyCodec_Lookup(encoding);
if (codecs == NULL) if (codecs == NULL)
goto onError; goto onError;
return build_stream_codec(PyTuple_GET_ITEM(codecs,2),stream,errors); ret = build_stream_codec(PyTuple_GET_ITEM(codecs,2),stream,errors);
Py_DECREF(codecs);
return ret;
onError: onError:
return NULL; return NULL;
@ -313,12 +317,14 @@ PyObject *PyCodec_StreamWriter(const char *encoding,
PyObject *stream, PyObject *stream,
const char *errors) const char *errors)
{ {
PyObject *codecs; PyObject *codecs, *ret;
codecs = _PyCodec_Lookup(encoding); codecs = _PyCodec_Lookup(encoding);
if (codecs == NULL) if (codecs == NULL)
goto onError; goto onError;
return build_stream_codec(PyTuple_GET_ITEM(codecs,3),stream,errors); ret = build_stream_codec(PyTuple_GET_ITEM(codecs,3),stream,errors);
Py_DECREF(codecs);
return ret;
onError: onError:
return NULL; return NULL;