Skip to content

LATX, fix: Release file streams on config and ELF exit paths - #507

Merged
LaurenIsACoder merged 3 commits into
lat-opensource:masterfrom
baibaidashixiong:dev_option_fd
Oct 15, 2026
Merged

LaurenIsACoder merged 3 commits into
lat-opensource:masterfrom
baibaidashixiong:dev_option_fd

Conversation

@baibaidashixiong

Copy link
Copy Markdown
Contributor

Summary / 变更说明

Fix file-descriptor leaks in LATX configuration parsing and ELF loading.
The valid parsing and library-loading paths keep their existing behavior and
ordering; file resources are only released after they are no longer needed or
when an error path returns early.

修复 LATX 配置解析和 ELF 加载路径中的文件描述符泄漏。正常配置解析和库加载
行为、查找顺序保持不变,只在资源不再需要或错误路径提前返回时释放文件资源。

  • 5ef3b671 load_conf_file(): close the configuration FILE after the
    parsing loop so normal EOF, early section break, and read-error exits release
    the descriptor. Each process opens at most the system and user config files.
  • 299ea156 loadElfFromFile(): close the ELF stream after
    LoadAndCheckElfHeader(), return NULL when header parsing fails, and clear
    the stored FILE/fd metadata before returning the header.
  • c4bc33db find_elf_rpath(): close the stream on stat() and header-parse
    failures, and close the raw descriptor when fdopen() fails.

Validation / 验证

  • Rebased onto lat-opensource/lat master 7cbdeb8f.
  • ./latxbuild/build-release.sh: passed.
  • meson test -C build64-tests-nokzt --suite lat-pr-fast --print-errorlogs:
    43/43 passed, 0 failed.
  • LoongArch runtime smoke tests with LATX_KZT=1 LATX_AOT=0:
    • /usr/gnemul/lat-x86_64/bin/true: exit status 0
    • dlopen("libm.so.6") guest: printed 1.000
    • guest with $ORIGIN/lib RPATH: printed 42
  • git diff --check: passed.

Checklist / 检查项

  • I have read CONTRIBUTING.md. / 我已阅读 CONTRIBUTING.md。
  • Every commit contains a DCO sign-off (git commit -s). /
    每个提交都包含 DCO 签署(git commit -s)。
  • I have included relevant build or test results, or explained why they
    are not applicable. /
    我已提供相关构建或测试结果,或说明了不适用的原因。

load_conf_file() freed the getline buffer but left the FILE stream open.
Close it after the parsing loop so normal EOF, early section break, and
read-error exits all release the descriptor. A process opens at most the
system and user configuration files.

Validation: x86_64-linux-user-latx-config-regression.
Signed-off-by: zqz <OrzZzznn@gmail.com>
loadElfFromFile() left the stream returned by fopen() open. It also
dereferenced a missing header when parsing failed.

Close the stream after LoadAndCheckElfHeader(), return early on parse
failure, and clear the stored FILE metadata before publishing the
header.

Signed-off-by: zqz <OrzZzznn@gmail.com>
find_elf_rpath() returned without closing the stream after stat() or
header parsing failed. It also leaked the raw descriptor when fdopen()
failed.

Close the stream on both error paths and close the raw descriptor when
fdopen() fails.

Signed-off-by: zqz <OrzZzznn@gmail.com>
@LaurenIsACoder
LaurenIsACoder merged commit bae9416 into lat-opensource:master Oct 15, 2026
15 checks passed
@baibaidashixiong
baibaidashixiong deleted the dev_option_fd branch October 16, 2026 01:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants