https://github.com/python/cpython/commit/e01a038972c4465abf02cfa87a31769960120a5a
commit: e01a038972c4465abf02cfa87a31769960120a5a
branch: 3.14
author: AN Long <[email protected]>
committer: StanFromIreland <[email protected]>
date: 2026-05-26T13:31:22Z
summary:
[3.14] gh-149931: Fix memory leaks on failed realloc (#150476)
(cherry picked from commit ec23ec6870373b64a760f4d7bcc3ed5495e1c9aa)
files:
M Modules/_remote_debugging_module.c
M Modules/timemodule.c
diff --git a/Modules/_remote_debugging_module.c
b/Modules/_remote_debugging_module.c
index d756ac326ff173..0b6b9d7f301a98 100644
--- a/Modules/_remote_debugging_module.c
+++ b/Modules/_remote_debugging_module.c
@@ -2459,12 +2459,14 @@ process_single_stack_chunk(
return -1;
}
- this_chunk = PyMem_RawRealloc(this_chunk, actual_size);
- if (!this_chunk) {
+ char *tmp = PyMem_RawRealloc(this_chunk, actual_size);
+ if (!tmp) {
+ PyMem_RawFree(this_chunk);
PyErr_NoMemory();
set_exception_cause(unwinder, PyExc_MemoryError, "Failed to
reallocate stack chunk buffer");
return -1;
}
+ this_chunk = tmp;
if (_Py_RemoteDebug_PagedReadRemoteMemory(&unwinder->handle,
chunk_addr, actual_size, this_chunk) < 0) {
PyMem_RawFree(this_chunk);
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index 1bfbf3f6a0b991..cbe7359524444a 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -820,12 +820,15 @@ time_strftime1(time_char **outbuf, size_t *bufsize,
PyErr_NoMemory();
return NULL;
}
- *outbuf = (time_char *)PyMem_Realloc(*outbuf,
- *bufsize*sizeof(time_char));
- if (*outbuf == NULL) {
+ time_char *tmp = (time_char *)PyMem_Realloc(*outbuf,
+
*bufsize*sizeof(time_char));
+ if (tmp == NULL) {
+ PyMem_Free(*outbuf);
+ *outbuf = NULL;
PyErr_NoMemory();
return NULL;
}
+ *outbuf = tmp;
#if defined _MSC_VER && _MSC_VER >= 1400 && defined(__STDC_SECURE_LIB__)
errno = 0;
#endif
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]