Skip to content

Commit 3133282

Browse files
vrabaudthewoz
authored andcommitted
Make sure AVIF decoder is destroyed in case of failure
1 parent 802feec commit 3133282

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

modules/imgcodecs/src/grfmt_avif.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include <avif/avif.h>
1010
#include <fstream>
11+
#include <memory>
1112

1213
#include <opencv2/core/utils/configuration.private.hpp>
1314
#include "opencv2/imgproc.hpp"
@@ -159,16 +160,16 @@ size_t AvifDecoder::signatureLength() const { return kAvifSignatureSize; }
159160
}
160161

161162
bool AvifDecoder::checkSignature(const String &signature) const {
162-
avifDecoder *decoder = avifDecoderCreate();
163+
std::unique_ptr<avifDecoder, decltype(&avifDecoderDestroy)> decoder(
164+
avifDecoderCreate(), avifDecoderDestroy);
163165
if (!decoder) return false;
164166
OPENCV_AVIF_CHECK_STATUS(
165167
avifDecoderSetIOMemory(
166-
decoder, reinterpret_cast<const uint8_t *>(signature.c_str()),
168+
decoder.get(), reinterpret_cast<const uint8_t *>(signature.c_str()),
167169
signature.size()),
168170
decoder);
169171
decoder->io->sizeHint = 1e9;
170-
const avifResult status = avifDecoderParse(decoder);
171-
avifDecoderDestroy(decoder);
172+
const avifResult status = avifDecoderParse(decoder.get());
172173
return (status == AVIF_RESULT_OK || status == AVIF_RESULT_TRUNCATED_DATA);
173174
}
174175

0 commit comments

Comments
 (0)