Skip to content

Commit

Permalink
Destroy image on failure
Browse files Browse the repository at this point in the history
  • Loading branch information
radarhere committed Dec 27, 2024
1 parent d406823 commit ea22f87
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/_avif.c
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,7 @@ AvifEncoderNew(PyObject *self_, PyObject *args) {
// Validate canvas dimensions
if (width <= 0 || height <= 0) {
PyErr_SetString(PyExc_ValueError, "invalid canvas dimensions");
avifImageDestroy(image);
return NULL;
}
image->width = width;
Expand Down Expand Up @@ -359,13 +360,15 @@ AvifEncoderNew(PyObject *self_, PyObject *args) {
if (advanced != Py_None) {
#if AVIF_VERSION >= 80200
if (_add_codec_specific_options(encoder, advanced)) {
avifImageDestroy(image);
avifEncoderDestroy(encoder);
return NULL;
}
#else
PyErr_SetString(
PyExc_ValueError, "Advanced codec options require libavif >= 0.8.2"
);
avifImageDestroy(image);
avifEncoderDestroy(encoder);
return NULL;
#endif
Expand All @@ -374,6 +377,7 @@ AvifEncoderNew(PyObject *self_, PyObject *args) {
self = PyObject_New(AvifEncoderObject, &AvifEncoder_Type);
if (!self) {
PyErr_SetString(PyExc_RuntimeError, "could not create encoder object");
avifImageDestroy(image);
avifEncoderDestroy(encoder);
return NULL;
}
Expand All @@ -397,6 +401,7 @@ AvifEncoderNew(PyObject *self_, PyObject *args) {
"Setting ICC profile failed: %s",
avifResultToString(result)
);
avifImageDestroy(image);
avifEncoderDestroy(encoder);
return NULL;
}
Expand All @@ -420,6 +425,7 @@ AvifEncoderNew(PyObject *self_, PyObject *args) {
"Setting EXIF data failed: %s",
avifResultToString(result)
);
avifImageDestroy(image);
avifEncoderDestroy(encoder);
return NULL;
}
Expand All @@ -437,6 +443,7 @@ AvifEncoderNew(PyObject *self_, PyObject *args) {
"Setting XMP data failed: %s",
avifResultToString(result)
);
avifImageDestroy(image);
avifEncoderDestroy(encoder);
return NULL;
}
Expand Down

0 comments on commit ea22f87

Please sign in to comment.