Kaydet (Commit) 322cc743 authored tarafından Victor Stinner's avatar Victor Stinner

Issue #17693: Fix memory/reference leaks

üst bf71f7d6
...@@ -738,7 +738,6 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx, ...@@ -738,7 +738,6 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
PyObject *inbuf = NULL; PyObject *inbuf = NULL;
Py_ssize_t inpos, datalen; Py_ssize_t inpos, datalen;
PyObject *origpending = NULL; PyObject *origpending = NULL;
wchar_t *data;
if (PyUnicode_Check(unistr)) if (PyUnicode_Check(unistr))
ucvt = NULL; ucvt = NULL;
...@@ -754,10 +753,6 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx, ...@@ -754,10 +753,6 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
} }
} }
data = PyUnicode_AsUnicodeAndSize(unistr, &datalen);
if (data == NULL)
goto errorexit;
if (ctx->pending) { if (ctx->pending) {
PyObject *inbuf_tmp; PyObject *inbuf_tmp;
...@@ -793,6 +788,7 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx, ...@@ -793,6 +788,7 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
origpending = NULL; origpending = NULL;
goto errorexit; goto errorexit;
} }
Py_XDECREF(origpending);
if (inpos < datalen) { if (inpos < datalen) {
if (datalen - inpos > MAXENCPENDING) { if (datalen - inpos > MAXENCPENDING) {
...@@ -808,6 +804,7 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx, ...@@ -808,6 +804,7 @@ encoder_encode_stateful(MultibyteStatefulEncoderContext *ctx,
} }
} }
Py_DECREF(inbuf);
Py_XDECREF(ucvt); Py_XDECREF(ucvt);
return r; return r;
...@@ -815,6 +812,7 @@ errorexit: ...@@ -815,6 +812,7 @@ errorexit:
Py_XDECREF(r); Py_XDECREF(r);
Py_XDECREF(ucvt); Py_XDECREF(ucvt);
Py_XDECREF(origpending); Py_XDECREF(origpending);
Py_XDECREF(inbuf);
return NULL; return NULL;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment