Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d03f9e5

Browse files
authored
Merge pull request #17263 from lawrence-danna-apple/cgdataprovider
you can't call CGDataProviderCreateWithData on a stack pointer
2 parents 9c28cea + c5d1c5a commit d03f9e5

File tree

1 file changed

+12
-12
lines changed

1 file changed

+12
-12
lines changed

src/_macosx.m

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1585,24 +1585,25 @@ - (void)setCanvas: (PyObject*)newCanvas
15851585

15861586
static void _buffer_release(void* info, const void* data, size_t size) {
15871587
PyBuffer_Release((Py_buffer *)info);
1588+
free(info);
15881589
}
15891590

15901591
static int _copy_agg_buffer(CGContextRef cr, PyObject *renderer)
15911592
{
1592-
Py_buffer buffer;
1593+
Py_buffer *buffer = malloc(sizeof(Py_buffer));
15931594

1594-
if (PyObject_GetBuffer(renderer, &buffer, PyBUF_CONTIG_RO) == -1) {
1595+
if (PyObject_GetBuffer(renderer, buffer, PyBUF_CONTIG_RO) == -1) {
15951596
PyErr_Print();
15961597
return 1;
15971598
}
15981599

1599-
if (buffer.ndim != 3 || buffer.shape[2] != 4) {
1600-
PyBuffer_Release(&buffer);
1600+
if (buffer->ndim != 3 || buffer->shape[2] != 4) {
1601+
_buffer_release(buffer, NULL, 0);
16011602
return 1;
16021603
}
16031604

1604-
const Py_ssize_t nrows = buffer.shape[0];
1605-
const Py_ssize_t ncols = buffer.shape[1];
1605+
const Py_ssize_t nrows = buffer->shape[0];
1606+
const Py_ssize_t ncols = buffer->shape[1];
16061607
const size_t bytesPerComponent = 1;
16071608
const size_t bitsPerComponent = 8 * bytesPerComponent;
16081609
const size_t nComponents = 4; /* red, green, blue, alpha */
@@ -1611,16 +1612,16 @@ static int _copy_agg_buffer(CGContextRef cr, PyObject *renderer)
16111612

16121613
CGColorSpaceRef colorspace = CGColorSpaceCreateWithName(kCGColorSpaceGenericRGB);
16131614
if (!colorspace) {
1614-
PyBuffer_Release(&buffer);
1615+
_buffer_release(buffer, NULL, 0);
16151616
return 1;
16161617
}
16171618

1618-
CGDataProviderRef provider = CGDataProviderCreateWithData(&buffer,
1619-
buffer.buf,
1620-
buffer.len,
1619+
CGDataProviderRef provider = CGDataProviderCreateWithData(buffer,
1620+
buffer->buf,
1621+
buffer->len,
16211622
_buffer_release);
16221623
if (!provider) {
1623-
PyBuffer_Release(&buffer);
1624+
_buffer_release(buffer, NULL, 0);
16241625
CGColorSpaceRelease(colorspace);
16251626
return 1;
16261627
}
@@ -1641,7 +1642,6 @@ static int _copy_agg_buffer(CGContextRef cr, PyObject *renderer)
16411642
CGDataProviderRelease(provider);
16421643

16431644
if (!bitmap) {
1644-
PyBuffer_Release(&buffer);
16451645
return 1;
16461646
}
16471647

0 commit comments

Comments
 (0)