We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
2 parents 42a852d + b3b0c82 commit 2a028c0Copy full SHA for 2a028c0
1 file changed
src/_image_wrapper.cpp
@@ -165,14 +165,22 @@ static PyObject *PyImage_color_conv(PyImage *self, PyObject *args, PyObject *kwd
165
return NULL;
166
}
167
168
- PyObject *result = PyBytes_FromStringAndSize(NULL, self->x->rowsOut * self->x->colsOut * 4);
169
- if (result == NULL) {
+ Py_ssize_t size = self->x->rowsOut * self->x->colsOut * 4;
+ agg::int8u *buff = (agg::int8u *)malloc(size);
170
+ if (buff == NULL) {
171
+ PyErr_SetString(PyExc_MemoryError, "Out of memory");
172
173
174
175
CALL_CPP_CLEANUP("color_conv",
- (self->x->color_conv(format, (agg::int8u *)PyBytes_AsString(result))),
- Py_DECREF(result));
176
+ (self->x->color_conv(format, buff)),
177
+ free(buff));
178
+
179
+ PyObject *result = PyByteArray_FromStringAndSize((const char *)buff, size);
180
+ if (result == NULL) {
181
+ free(buff);
182
+ return NULL;
183
+ }
184
185
return Py_BuildValue("nnN", self->x->rowsOut, self->x->colsOut, result);
186
0 commit comments