Skip to content

Commit c6e7431

Browse files
miss-islingtonKowalskiThomasStanFromIreland
authored
[3.15] gh-151126: Set MemoryError on allocation failure in CJK codec macros (GH-156292) (#160674)
(cherry picked from commit d441a11) Co-authored-by: Thomas Kowalski <thom.kowa@gmail.com> Co-authored-by: Stan Ulbrych <stan@python.org>
1 parent 81d08d1 commit c6e7431

2 files changed

Lines changed: 4 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a crash caused by failing to set :exc:`MemoryError` on allocation
2+
failure when first using a Chinese, Japanese or Korean codec.

‎Modules/cjkcodecs/cjkcodecs.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,7 @@ add_mappings(cjkcodecs_module_state *st) \
237237
st->num_mappings = NUM; \
238238
st->mapping_list = PyMem_Calloc(NUM, sizeof(struct dbcs_map)); \
239239
if (st->mapping_list == NULL) { \
240+
PyErr_NoMemory(); \
240241
return -1; \
241242
}
242243

@@ -261,6 +262,7 @@ add_codecs(cjkcodecs_module_state *st) \
261262
st->num_codecs = NUM; \
262263
st->codec_list = PyMem_Calloc(NUM, sizeof(MultibyteCodec)); \
263264
if (st->codec_list == NULL) { \
265+
PyErr_NoMemory(); \
264266
return -1; \
265267
}
266268

0 commit comments

Comments
 (0)