Skip to content

Commit 9c9fece

Browse files
authored
Check realloc return value (#9722)
1 parent f7a31ea commit 9c9fece

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

src/path.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -343,11 +343,14 @@ path_compact(PyPathObject *self, PyObject *args) {
343343
}
344344

345345
i = self->count - j;
346-
self->count = j;
347346

348347
/* shrink coordinate array */
349-
/* malloc check ok, self->count is smaller than it was before */
350-
self->xy = realloc(self->xy, 2 * self->count * sizeof(double));
348+
double *new_xy = realloc(self->xy, 2 * j * sizeof(double));
349+
if (!new_xy) {
350+
return ImagingError_MemoryError();
351+
}
352+
self->xy = new_xy;
353+
self->count = j;
351354

352355
return Py_BuildValue("i", i); /* number of removed vertices */
353356
}

0 commit comments

Comments
 (0)