Skip to content

Commit a2eb537

Browse files
using PyMem_Malloc to allocate memory instead of stack
1 parent 5110979 commit a2eb537

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

‎Objects/bytearrayobject.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2468,11 +2468,20 @@ bytearray_strip_impl_helper(PyByteArrayObject* self, PyObject* bytes, int stript
24682468
} while (right >= left && memchr(bytesptr, (unsigned char)myptr[right], byteslen));
24692469
right++;
24702470
}
2471-
char temp_ptr[mysize+1];
2471+
2472+
char *temp_ptr = PyMem_Malloc(mysize+1);
2473+
2474+
if(temp_ptr == NULL) {
2475+
return PyErr_NoMemory();
2476+
}
2477+
24722478
strncpy(temp_ptr,myptr, mysize);
2479+
24732480
if (bytes != Py_None)
24742481
PyBuffer_Release(&vbytes);
2475-
return PyByteArray_FromStringAndSize(temp_ptr + left, right - left);
2482+
PyObject *res = PyByteArray_FromStringAndSize(temp_ptr + left, right - left);
2483+
PyMem_Free(temp_ptr);
2484+
return res;
24762485
}
24772486

24782487
/*[clinic input]

0 commit comments

Comments
 (0)