From 6ae41c89dc719dc2d5e99cf13bbc073b4e0dd64f Mon Sep 17 00:00:00 2001 From: Thomas Kowalski Date: Sun, 23 Aug 2026 16:33:25 +0200 Subject: [PATCH] gh-151126: Set MemoryError on alloc failure in CJK codec macros --- .../next/Library/2026-08-23-16-33-00.gh-issue-151126.GUvtG7.rst | 2 ++ Modules/cjkcodecs/cjkcodecs.h | 2 ++ 2 files changed, 4 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2026-08-23-16-33-00.gh-issue-151126.GUvtG7.rst diff --git a/Misc/NEWS.d/next/Library/2026-08-23-16-33-00.gh-issue-151126.GUvtG7.rst b/Misc/NEWS.d/next/Library/2026-08-23-16-33-00.gh-issue-151126.GUvtG7.rst new file mode 100644 index 00000000000000..0307bcdbfc3278 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-23-16-33-00.gh-issue-151126.GUvtG7.rst @@ -0,0 +1,2 @@ +Raise :exc:`MemoryError` on allocation failure during CJK codec module +initialisation. diff --git a/Modules/cjkcodecs/cjkcodecs.h b/Modules/cjkcodecs/cjkcodecs.h index 9d86396f73b2b5..f1e92fe7974a6d 100644 --- a/Modules/cjkcodecs/cjkcodecs.h +++ b/Modules/cjkcodecs/cjkcodecs.h @@ -237,6 +237,7 @@ add_mappings(cjkcodecs_module_state *st) \ st->num_mappings = NUM; \ st->mapping_list = PyMem_Calloc(NUM, sizeof(struct dbcs_map)); \ if (st->mapping_list == NULL) { \ + PyErr_NoMemory(); \ return -1; \ } @@ -261,6 +262,7 @@ add_codecs(cjkcodecs_module_state *st) \ st->num_codecs = NUM; \ st->codec_list = PyMem_Calloc(NUM, sizeof(MultibyteCodec)); \ if (st->codec_list == NULL) { \ + PyErr_NoMemory(); \ return -1; \ }