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

Skip to content

Commit f72d4ef

Browse files
committed
Plug some (unlikely) refleaks.
1 parent 61093c0 commit f72d4ef

1 file changed

Lines changed: 45 additions & 15 deletions

File tree

Modules/_codecsmodule.c

Lines changed: 45 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -720,8 +720,10 @@ utf_7_encode(PyObject *self,
720720
return NULL;
721721

722722
str = PyUnicode_FromObject(str);
723-
if (str == NULL || PyUnicode_READY(str) < 0)
723+
if (str == NULL || PyUnicode_READY(str) < 0) {
724+
Py_XDECREF(str);
724725
return NULL;
726+
}
725727
v = codec_tuple(_PyUnicode_EncodeUTF7(str, 0, 0, errors),
726728
PyUnicode_GET_LENGTH(str));
727729
Py_DECREF(str);
@@ -740,8 +742,10 @@ utf_8_encode(PyObject *self,
740742
return NULL;
741743

742744
str = PyUnicode_FromObject(str);
743-
if (str == NULL || PyUnicode_READY(str) == -1)
745+
if (str == NULL || PyUnicode_READY(str) < 0) {
746+
Py_XDECREF(str);
744747
return NULL;
748+
}
745749
v = codec_tuple(PyUnicode_AsEncodedString(str, "utf-8", errors),
746750
PyUnicode_GET_LENGTH(str));
747751
Py_DECREF(str);
@@ -768,8 +772,10 @@ utf_16_encode(PyObject *self,
768772
return NULL;
769773

770774
str = PyUnicode_FromObject(str);
771-
if (str == NULL || PyUnicode_READY(str) < 0)
775+
if (str == NULL || PyUnicode_READY(str) < 0) {
776+
Py_XDECREF(str);
772777
return NULL;
778+
}
773779
v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, byteorder),
774780
PyUnicode_GET_LENGTH(str));
775781
Py_DECREF(str);
@@ -788,8 +794,10 @@ utf_16_le_encode(PyObject *self,
788794
return NULL;
789795

790796
str = PyUnicode_FromObject(str);
791-
if (str == NULL || PyUnicode_READY(str) < 0)
797+
if (str == NULL || PyUnicode_READY(str) < 0) {
798+
Py_XDECREF(str);
792799
return NULL;
800+
}
793801
v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, -1),
794802
PyUnicode_GET_LENGTH(str));
795803
Py_DECREF(str);
@@ -808,8 +816,10 @@ utf_16_be_encode(PyObject *self,
808816
return NULL;
809817

810818
str = PyUnicode_FromObject(str);
811-
if (str == NULL || PyUnicode_READY(str) < 0)
819+
if (str == NULL || PyUnicode_READY(str) < 0) {
820+
Py_XDECREF(str);
812821
return NULL;
822+
}
813823
v = codec_tuple(_PyUnicode_EncodeUTF16(str, errors, +1),
814824
PyUnicode_GET_LENGTH(str));
815825
Py_DECREF(str);
@@ -836,8 +846,10 @@ utf_32_encode(PyObject *self,
836846
return NULL;
837847

838848
str = PyUnicode_FromObject(str);
839-
if (str == NULL || PyUnicode_READY(str) < 0)
849+
if (str == NULL || PyUnicode_READY(str) < 0) {
850+
Py_XDECREF(str);
840851
return NULL;
852+
}
841853
v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, byteorder),
842854
PyUnicode_GET_LENGTH(str));
843855
Py_DECREF(str);
@@ -856,8 +868,10 @@ utf_32_le_encode(PyObject *self,
856868
return NULL;
857869

858870
str = PyUnicode_FromObject(str);
859-
if (str == NULL || PyUnicode_READY(str) < 0)
871+
if (str == NULL || PyUnicode_READY(str) < 0) {
872+
Py_XDECREF(str);
860873
return NULL;
874+
}
861875
v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, -1),
862876
PyUnicode_GET_LENGTH(str));
863877
Py_DECREF(str);
@@ -876,8 +890,10 @@ utf_32_be_encode(PyObject *self,
876890
return NULL;
877891

878892
str = PyUnicode_FromObject(str);
879-
if (str == NULL || PyUnicode_READY(str) < 0)
893+
if (str == NULL || PyUnicode_READY(str) < 0) {
894+
Py_XDECREF(str);
880895
return NULL;
896+
}
881897
v = codec_tuple(_PyUnicode_EncodeUTF32(str, errors, +1),
882898
PyUnicode_GET_LENGTH(str));
883899
Py_DECREF(str);
@@ -896,8 +912,10 @@ unicode_escape_encode(PyObject *self,
896912
return NULL;
897913

898914
str = PyUnicode_FromObject(str);
899-
if (str == NULL || PyUnicode_READY(str) < 0)
915+
if (str == NULL || PyUnicode_READY(str) < 0) {
916+
Py_XDECREF(str);
900917
return NULL;
918+
}
901919
v = codec_tuple(PyUnicode_AsUnicodeEscapeString(str),
902920
PyUnicode_GET_LENGTH(str));
903921
Py_DECREF(str);
@@ -916,8 +934,10 @@ raw_unicode_escape_encode(PyObject *self,
916934
return NULL;
917935

918936
str = PyUnicode_FromObject(str);
919-
if (str == NULL || PyUnicode_READY(str) < 0)
937+
if (str == NULL || PyUnicode_READY(str) < 0) {
938+
Py_XDECREF(str);
920939
return NULL;
940+
}
921941
v = codec_tuple(PyUnicode_AsRawUnicodeEscapeString(str),
922942
PyUnicode_GET_LENGTH(str));
923943
Py_DECREF(str);
@@ -936,8 +956,10 @@ latin_1_encode(PyObject *self,
936956
return NULL;
937957

938958
str = PyUnicode_FromObject(str);
939-
if (str == NULL || PyUnicode_READY(str) < 0)
959+
if (str == NULL || PyUnicode_READY(str) < 0) {
960+
Py_XDECREF(str);
940961
return NULL;
962+
}
941963
v = codec_tuple(_PyUnicode_AsLatin1String(str, errors),
942964
PyUnicode_GET_LENGTH(str));
943965
Py_DECREF(str);
@@ -956,8 +978,10 @@ ascii_encode(PyObject *self,
956978
return NULL;
957979

958980
str = PyUnicode_FromObject(str);
959-
if (str == NULL || PyUnicode_READY(str) < 0)
981+
if (str == NULL || PyUnicode_READY(str) < 0) {
982+
Py_XDECREF(str);
960983
return NULL;
984+
}
961985
v = codec_tuple(_PyUnicode_AsASCIIString(str, errors),
962986
PyUnicode_GET_LENGTH(str));
963987
Py_DECREF(str);
@@ -979,8 +1003,10 @@ charmap_encode(PyObject *self,
9791003
mapping = NULL;
9801004

9811005
str = PyUnicode_FromObject(str);
982-
if (str == NULL || PyUnicode_READY(str) < 0)
1006+
if (str == NULL || PyUnicode_READY(str) < 0) {
1007+
Py_XDECREF(str);
9831008
return NULL;
1009+
}
9841010
v = codec_tuple(_PyUnicode_EncodeCharmap(str, mapping, errors),
9851011
PyUnicode_GET_LENGTH(str));
9861012
Py_DECREF(str);
@@ -1010,8 +1036,10 @@ mbcs_encode(PyObject *self,
10101036
return NULL;
10111037

10121038
str = PyUnicode_FromObject(str);
1013-
if (str == NULL || PyUnicode_READY(str) < 0)
1039+
if (str == NULL || PyUnicode_READY(str) < 0) {
1040+
Py_XDECREF(str);
10141041
return NULL;
1042+
}
10151043
v = codec_tuple(PyUnicode_EncodeCodePage(CP_ACP, str, errors),
10161044
PyUnicode_GET_LENGTH(str));
10171045
Py_DECREF(str);
@@ -1031,8 +1059,10 @@ code_page_encode(PyObject *self,
10311059
return NULL;
10321060

10331061
str = PyUnicode_FromObject(str);
1034-
if (str == NULL || PyUnicode_READY(str) < 0)
1062+
if (str == NULL || PyUnicode_READY(str) < 0) {
1063+
Py_XDECREF(str);
10351064
return NULL;
1065+
}
10361066
v = codec_tuple(PyUnicode_EncodeCodePage(code_page,
10371067
str,
10381068
errors),

0 commit comments

Comments
 (0)