Memory Leak in Kpathsea

Jonathan Gruber <[email protected]> Mon, 15 Jun 2026 22:23:51 -0700
Newsgroups gmane.comp.tex.live
Message-ID <CAGKpfjp16oCdJZvqUY8yU0KVCujiwSo+HT0sj9OM==tg0PfHoQ@mail.gmail.com>
Hello.

In the file Build/source/texk/kpathsea/cnf.c, in the function
read_all_cnf, there appears to be a memory leak. If I understand
correctly, the variable cnf_files, if nonnull, points to dynamically
allocated memory. In the case that the expression cnf_files &&
*cnf_files evaluates to true, i.e., when cnf_files is nonnull and
*cnf_files is also nonnull, read_all_cnf eventually calls free upon
cnf_files. Otherwise, i.e., either when cnf_files is null or when
cnf_files is nonnull but *cnf_files is null, read_all_cnf never calls
free upon cnf_files. As a result, when cnf_files is nonnull but
*cnf_files is null, the memory pointed to by cnf_files is never freed,
resulting in a memory leak. At least from my skimming of the source
code of the function kpathsea_all_path_search, whose return value
cnf_files is set to, it would be the case that cnf_files is nonnull
while *cnf_files is null if cnf_files points to an empty list of
strings.

All my observations are based upon the latest version (at time of
writing) of the trunk branch of TeX Live's Subversion repository.

Thank you,
Jonathan Gruber