libheif icon indicating copy to clipboard operation
libheif copied to clipboard

Possible leak in x265 while decoding

Open pierrejoye opened this issue 3 years ago • 3 comments

Example code, relatively classic usage:

https://github.com/libgd/libgd/blob/master/src/gd_heif.c#L113

I can only reproduce using one of our tests (other do not have this leak):

https://github.com/libgd/libgd/blob/master/tests/heif/heif_im2im.c#L36

which reads using heif_context_read_from_memory_without_copy.

I am not completely sure where the allocations (2x leak):

================================================================= ==31634==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 2048 byte(s) in 2 object(s) allocated from: #0 0x7f049d924aa5 in posix_memalign (/lib/x86_64-linux-gnu/libasan.so.5+0x10eaa5) #1 0x7f049c33eb47 in x265::x265_malloc(unsigned long) (/lib/x86_64-linux-gnu/libx265.so.179+0x45db47)

SUMMARY: AddressSanitizer: 2048 byte(s) leaked in 2 allocation(s).

I also attached the valgrind log (ran it too), but there may be a lot of false positive, or a lot of other issues in x265 ;-)

vg_logfile.txt

I also get that one using decoding on reading from gdSurfaceCreateFromHeif (same file as above), in the vg_logfile_read.txt. vg_logfile_read.txt

Master and 1.12.0

may be related to https://github.com/strukturag/libheif/issues/531

pierrejoye avatar Aug 13 '21 07:08 pierrejoye

Same in encoding

================================================================= ==32711==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 2048 byte(s) in 2 object(s) allocated from: #0 0x7f2f7c195aa5 in posix_memalign (/lib/x86_64-linux-gnu/libasan.so.5+0x10eaa5) #1 0x7f2f7ab92b47 in x265::x265_malloc(unsigned long) (/lib/x86_64-linux-gnu/libx265.so.179+0x45db47)

SUMMARY: AddressSanitizer: 2048 byte(s) leaked in 2 allocation(s).

pierrejoye avatar Aug 13 '21 09:08 pierrejoye

Additional info, expected ;) image

image

libde265_free_decoder or other are never used.

What was the idea or design behind it? As it may matter less in CLI apps, it is absolutely critical to free them in server environments. Happy to work on a PR however I would need to know what was the idea here :)

pierrejoye avatar Aug 22 '21 06:08 pierrejoye

@pierrejoye Are you still seeing this problem?

bradh avatar Dec 22 '23 06:12 bradh