Probably not really an issue when using software encoders, but might be more complicated if there is hardware involved.

```
$ valgrind --leak-check=full ./examples/heif-enc --params --encoder x265 /usr/share/wallpapers/Dance_of_the_Spirits/contents/images/2560x1600.jpg -o out.heif
==17583== Memcheck, a memory error detector
==17583== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==17583== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==17583== Command: ./examples/heif-enc --params --encoder x265 /usr/share/wallpapers/Dance_of_the_Spirits/contents/images/2560x1600.jpg -o out.heif
==17583== 
Parameters for encoder `x265 HEVC encoder (3.5+1-f0c1022b6)`:
  quality, default=50, [0;100]
  lossless, default=false
  preset, default=slow, { ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placebo }
  tune, default=ssim, { psnr,ssim,grain,fastdecode }
  tu-intra-depth, default=2, [1;4]
  complexity, [0;100]
  chroma, default=420, { 420,422,444 }
==17583== 
==17583== HEAP SUMMARY:
==17583==     in use at exit: 464 bytes in 3 blocks
==17583==   total heap usage: 207 allocs, 204 frees, 174,935 bytes allocated
==17583== 
==17583== 464 (16 direct, 448 indirect) bytes in 1 blocks are definitely lost in loss record 3 of 3
==17583==    at 0x4845FA3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==17583==    by 0x48F0934: heif_context_get_encoder (heif.cc:2133)
==17583==    by 0x111603: main (heif_enc.cc:716)
==17583== 
==17583== LEAK SUMMARY:
==17583==    definitely lost: 16 bytes in 1 blocks
==17583==    indirectly lost: 448 bytes in 2 blocks
==17583==      possibly lost: 0 bytes in 0 blocks
==17583==    still reachable: 0 bytes in 0 blocks
==17583==         suppressed: 0 bytes in 0 blocks
==17583== 
==17583== For lists of detected and suppressed errors, rerun with: -s
==17583== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
```
heif-enc leaks encoder when using --params
This is a GitHub Issue
repo:libheif
owner:strukturag
Title : heif-enc leaks encoder when using --params
Issue date:

--- start body ---
Probably not really an issue when using software encoders, but might be more complicated if there is hardware involved.

```
$ valgrind --leak-check=full ./examples/heif-enc --params --encoder x265 /usr/share/wallpapers/Dance_of_the_Spirits/contents/images/2560x1600.jpg -o out.heif
==17583== Memcheck, a memory error detector
==17583== Copyright (C) 2002-2022, and GNU GPL'd, by Julian Seward et al.
==17583== Using Valgrind-3.21.0 and LibVEX; rerun with -h for copyright info
==17583== Command: ./examples/heif-enc --params --encoder x265 /usr/share/wallpapers/Dance_of_the_Spirits/contents/images/2560x1600.jpg -o out.heif
==17583== 
Parameters for encoder `x265 HEVC encoder (3.5+1-f0c1022b6)`:
  quality, default=50, [0;100]
  lossless, default=false
  preset, default=slow, { ultrafast,superfast,veryfast,faster,fast,medium,slow,slower,veryslow,placebo }
  tune, default=ssim, { psnr,ssim,grain,fastdecode }
  tu-intra-depth, default=2, [1;4]
  complexity, [0;100]
  chroma, default=420, { 420,422,444 }
==17583== 
==17583== HEAP SUMMARY:
==17583==     in use at exit: 464 bytes in 3 blocks
==17583==   total heap usage: 207 allocs, 204 frees, 174,935 bytes allocated
==17583== 
==17583== 464 (16 direct, 448 indirect) bytes in 1 blocks are definitely lost in loss record 3 of 3
==17583==    at 0x4845FA3: operator new(unsigned long) (in /usr/libexec/valgrind/vgpreload_memcheck-amd64-linux.so)
==17583==    by 0x48F0934: heif_context_get_encoder (heif.cc:2133)
==17583==    by 0x111603: main (heif_enc.cc:716)
==17583== 
==17583== LEAK SUMMARY:
==17583==    definitely lost: 16 bytes in 1 blocks
==17583==    indirectly lost: 448 bytes in 2 blocks
==17583==      possibly lost: 0 bytes in 0 blocks
==17583==    still reachable: 0 bytes in 0 blocks
==17583==         suppressed: 0 bytes in 0 blocks
==17583== 
==17583== For lists of detected and suppressed errors, rerun with: -s
==17583== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)
```
--- end body ---

The issue describes a memory leak in the heif-enc tool when using the x265 encoder with specific parameters. The Valgrind output indicates that there are 464 bytes in use at exit, with 16 bytes definitely lost, which suggests that the application does not properly free memory allocated during its execution. This could lead to increased memory usage over time, especially in long-running processes or when processing multiple files.