Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitebf5459

Browse files
[3.14]gh-140939: Fix memory leak in_PyBytes_FormatEx error path (GH-140957) (#141154)
(cherry picked from commitd6c89a2)
1 parent5d10409 commitebf5459

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

‎Lib/test/test_bytes.py‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,13 @@ def __int__(self):
802802
withself.assertRaisesRegex(TypeError,msg):
803803
operator.mod(format_bytes,value)
804804

805+
deftest_memory_leak_gh_140939(self):
806+
# gh-140939: MemoryError is raised without leaking
807+
_testcapi=import_helper.import_module('_testcapi')
808+
withself.assertRaises(MemoryError):
809+
b=self.type2test(b'%*b')
810+
b% (_testcapi.PY_SSIZE_T_MAX,b'abc')
811+
805812
deftest_imod(self):
806813
b=self.type2test(b'hello, %b!')
807814
orig=b
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix memory leak when:class:`bytearray` or:class:`bytes` is formated with the
2+
``%*b`` format with a large width that results in a:exc:`MemoryError`.

‎Objects/bytesobject.c‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -975,8 +975,10 @@ _PyBytes_FormatEx(const char *format, Py_ssize_t format_len,
975975
/* 2: size preallocated for %s */
976976
if (alloc>2) {
977977
res=_PyBytesWriter_Prepare(&writer,res,alloc-2);
978-
if (res==NULL)
978+
if (res==NULL) {
979+
Py_XDECREF(temp);
979980
gotoerror;
981+
}
980982
}
981983
#ifndefNDEBUG
982984
char*before=res;

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp