From 59c3f039448310f0048a5656f12eb49f2912775a Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 20 Jun 2026 10:00:56 +1000 Subject: [PATCH] Check PyCapsule_New return value --- src/_imaging.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/_imaging.c b/src/_imaging.c index 12cd3ddc753..fc7055e150c 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -272,7 +272,15 @@ ExportArrowSchemaPyCapsule(ImagingObject *self) { } int err = export_imaging_schema(self->image, schema); if (err == 0) { - return PyCapsule_New(schema, "arrow_schema", ReleaseArrowSchemaPyCapsule); + PyObject *capsule = + PyCapsule_New(schema, "arrow_schema", ReleaseArrowSchemaPyCapsule); + if (capsule == NULL) { + if (schema->release != NULL) { + schema->release(schema); + } + free(schema); + } + return capsule; } free(schema); return ArrowError(err); @@ -300,7 +308,15 @@ ExportArrowArrayPyCapsule(ImagingObject *self) { } int err = export_imaging_array(self->image, array); if (err == 0) { - return PyCapsule_New(array, "arrow_array", ReleaseArrowArrayPyCapsule); + PyObject *capsule = + PyCapsule_New(array, "arrow_array", ReleaseArrowArrayPyCapsule); + if (capsule == NULL) { + if (array->release != NULL) { + array->release(array); + } + free(array); + } + return capsule; } free(array); return ArrowError(err);