with self.assertRaisesRegex(TypeError, msg):
operator.mod(format_bytes, value)
+ def test_memory_leak_gh_140939(self):
+ # gh-140939: MemoryError is raised without leaking
+ _testcapi = import_helper.import_module('_testcapi')
+ with self.assertRaises(MemoryError):
+ b = self.type2test(b'%*b')
+ b % (_testcapi.PY_SSIZE_T_MAX, b'abc')
+
def test_imod(self):
b = self.type2test(b'hello, %b!')
orig = b
/* 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;