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

Skip to content

Commit afb1cb5

Browse files
Issue #16971: Fix a refleak in the charmap decoder.
1 parent 1e49dde commit afb1cb5

1 file changed

Lines changed: 13 additions & 4 deletions

File tree

Objects/unicodeobject.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7510,23 +7510,29 @@ PyUnicode_DecodeCharmap(const char *s,
75107510
Py_DECREF(x);
75117511
goto onError;
75127512
}
7513-
if (unicode_putchar(&v, &outpos, value) < 0)
7513+
if (unicode_putchar(&v, &outpos, value) < 0) {
7514+
Py_DECREF(x);
75147515
goto onError;
7516+
}
75157517
}
75167518
else if (PyUnicode_Check(x)) {
75177519
Py_ssize_t targetsize;
75187520

7519-
if (PyUnicode_READY(x) == -1)
7521+
if (PyUnicode_READY(x) == -1) {
7522+
Py_DECREF(x);
75207523
goto onError;
7524+
}
75217525
targetsize = PyUnicode_GET_LENGTH(x);
75227526

75237527
if (targetsize == 1) {
75247528
/* 1-1 mapping */
75257529
Py_UCS4 value = PyUnicode_READ_CHAR(x, 0);
75267530
if (value == 0xFFFE)
75277531
goto Undefined;
7528-
if (unicode_putchar(&v, &outpos, value) < 0)
7532+
if (unicode_putchar(&v, &outpos, value) < 0) {
7533+
Py_DECREF(x);
75297534
goto onError;
7535+
}
75307536
}
75317537
else if (targetsize > 1) {
75327538
/* 1-n mapping */
@@ -7543,8 +7549,11 @@ PyUnicode_DecodeCharmap(const char *s,
75437549
goto onError;
75447550
}
75457551
}
7546-
if (unicode_widen(&v, outpos, PyUnicode_MAX_CHAR_VALUE(x)) < 0)
7552+
if (unicode_widen(&v, outpos,
7553+
PyUnicode_MAX_CHAR_VALUE(x)) < 0) {
7554+
Py_DECREF(x);
75477555
goto onError;
7556+
}
75487557
PyUnicode_CopyCharacters(v, outpos, x, 0, targetsize);
75497558
outpos += targetsize;
75507559
extrachars -= targetsize;

0 commit comments

Comments
 (0)