[3.14] gh-140939: Fix memory leak in _PyBytes_FormatEx error path (GH-140957) (#141154)

(cherry picked from commit d6c89a2df2)
This commit is contained in:
Stan Ulbrych 2025-11-06 16:20:03 +00:00 committed by GitHub
parent 5d10409e33
commit ebf54596bf
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 12 additions and 1 deletions

View file

@ -975,8 +975,10 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
/* 2: size preallocated for %s */
if (alloc > 2) {
res = _PyBytesWriter_Prepare(&writer, res, alloc - 2);
if (res == NULL)
if (res == NULL) {
Py_XDECREF(temp);
goto error;
}
}
#ifndef NDEBUG
char *before = res;