Commit 811cb490 for libheif

commit 811cb490057acda19837e640a248404ea689efe4
Author: Dirk Farin <dirk.farin@gmail.com>
Date:   Tue Sep 29 23:21:00 2026 +0200

    heif-enc: release the encoder and the encoding options on every exit

    heif-enc creates the encoder before it checks whether there is an input file.
    Without one, it printed the help and returned without releasing the encoder,
    which LeakSanitizer reports. The error path after writing the file did not
    release the encoder and the encoding options either.

    Both are owned by smart pointers now, like the context.

diff --git a/examples/heif_enc.cc b/examples/heif_enc.cc
index a46e0d9f..c8a51ca0 100644
--- a/examples/heif_enc.cc
+++ b/examples/heif_enc.cc
@@ -2052,9 +2052,12 @@ int main(int argc, char** argv)
     return 5;
   }

+  // Releases the encoder on every way out of main(). This is defined after the context, so
+  // the encoder is released before the context is freed.
+  std::unique_ptr<heif_encoder, void (*)(heif_encoder*)> encoder_releaser(encoder, heif_encoder_release);
+
   if (option_show_parameters) {
     list_encoder_parameters(encoder);
-    heif_encoder_release(encoder);
     return 0;
   }

@@ -2101,6 +2104,8 @@ int main(int argc, char** argv)

   set_params(encoder, raw_params);
   struct heif_encoding_options* options = heif_encoding_options_alloc();
+  std::unique_ptr<heif_encoding_options, void (*)(heif_encoding_options*)> options_releaser(options, heif_encoding_options_free);
+
   options->save_two_colr_boxes_when_ICC_and_nclx_available = (uint8_t) two_colr_boxes;

   if (chroma_downsampling == "average") {
@@ -2153,8 +2158,6 @@ int main(int argc, char** argv)
   }

   if (ret != 0) {
-    heif_encoding_options_free(options);
-    heif_encoder_release(encoder);
     return ret;
   }

@@ -2162,8 +2165,6 @@ int main(int argc, char** argv)

   ret = add_mime_item(context.get());
   if (ret != 0) {
-    heif_encoding_options_free(options);
-    heif_encoder_release(encoder);
     return ret;
   }

@@ -2180,9 +2181,6 @@ int main(int argc, char** argv)
     return 5;
   }

-  heif_encoding_options_free(options);
-  heif_encoder_release(encoder);
-
   return 0;
 }