[tex-live] memory leak with kpathsea_find_file() ?
vincent.torri at gmail.com
Mon Jun 27 07:30:10 CEST 2016
On Sun, Jun 26, 2016 at 11:48 PM, Karl Berry <karl at freefriends.org> wrote:
> n = kpathsea_find_file(kpse, name, kpse_tfm_format, 1);
> trying to free 'n' with free() leads to errors
> I don't understand that. As far as I can recall, kpathsea_find_file
> should always return newly-malloced memory, aside perhaps from
> pathological cases, certainly not yours.
if I free the result given by kpathsea_find_file(), after
kpathsea_finish(), i get :
Error #1: INVALID HEAP ARGUMENT to free 0x03bec028
# 0 replace_free
# 1 libdvi-0.dll!dvi_font_define [src/lib/dvi_font.c:342]
# 2 libdvi-0.dll!dvi_interpreter_fnt_def_parse
# 3 libdvi-0.dll!dvi_interpreter_postamble_parse
# 4 libdvi-0.dll!dvi_document_new [src/lib/dvi_document.c:153]
# 5 main [src/bin/dvi.c:16]
Note: @0:00:27.083 in thread 2704
Note: refers to -1 byte(s) before next malloc
Note: next higher malloc: 0x03bec028-0x03bec07f
Note: refers to -87 byte(s) beyond last valid byte in prior malloc
Note: prev lower malloc: 0x03bec028-0x03bec07f
The code is equivalent to this:
kpse = kpathsea_new();
kpathsea_set_program_name(kpse, "kpsewhich", NULL);
kpathsea_init_prog (kpse, "LIBDVI", 300, NULL, NULL);
n = kpathsea_find_file(kpse, name, kpse_tfm_format, 1);
/* i do something */
> Is this unfreed memory normal ?
> Yes, it is normal. I never tried to make kpse 100% memory efficient.
> A few lost bytes did not matter in 1986, and they matter even less now.
> or my code is not fully correct ?
> Your code looks ok to me. -k
More information about the tex-live