Skip to content

Free file metadata discarded by successful gathers (#379) - #382

Merged
jiegec merged 4 commits into
lsof-org:masterfrom
hugojosealmeida:sdlc/issue-379-free-gather-file-metadata
Nov 3, 2026
Merged

jiegec merged 4 commits into
lsof-org:masterfrom
hugojosealmeida:sdlc/issue-379-free-gather-file-metadata

Conversation

@hugojosealmeida

Copy link
Copy Markdown
Contributor

Summary

Free file metadata discarded by successful lsof_gather calls while preserving transferred result names.

Changes

  • Release untransferred names and filesystem strings.
  • Make the Solaris fsdev fallback an owned copy.
  • Add regression coverage for selected and filtered files.

Verification

  • make check TESTS=tests/LTfilemeta: pass.
  • Test and lib/lsof.c instrumented with ASan + UBSan: pass.
  • Darwin leaks: 84 leaks / 7,632 bytes before; 3 / 4,128 after. Metadata allocation stacks disappeared; separate Darwin gather-buffer leaks remain.

This PR is AI Assisted.

Closes #379

@hugojosealmeida

Copy link
Copy Markdown
Contributor Author

I have reproduced on Darwin: three filtered gathers reported 84 leaks / 7,632 bytes. With the fix, that dropped to 3 leaks / 4,128 bytes; the allocation stacks for nm, fsdir, and fsdev disappeared.
The remaining leaks seems to be Darwin gather buffers outside this fix. I have added a test that also confirms that selected names survive context destruction and the filtered FD is not returned.

hugojosealmeida added a commit to hugojosealmeida/lsof that referenced this pull request Nov 2, 2026
@hugojosealmeida

Copy link
Copy Markdown
Contributor Author

The new test requires an exact pathname match and so maybe the failure is likely a portability issue in the test I added: the existing LTbasic2 explicitly calls stat() after file creation to make FreeBSD expose the pathname. I will investigate.

@hugojosealmeida

Copy link
Copy Markdown
Contributor Author

Found it, the test assumes name is a raw pathname, but FreeBSD appends filesystem information. Its exact strcmp()therefore rejects a valid result. The fix on the test changes that comparison tostrstr()` (and adds a comment).

@jiegec

jiegec commented Nov 3, 2026

Copy link
Copy Markdown
Member

Please rebase, and I think it is unnecessary to write a test for this.

@hugojosealmeida
hugojosealmeida force-pushed the sdlc/issue-379-free-gather-file-metadata branch from 83946bf to a9b629a Compare November 3, 2026 02:29
@jiegec
jiegec merged commit 8d40ca5 into lsof-org:master Nov 3, 2026
17 checks passed
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.

Free file metadata discarded by successful lsof_gather calls

2 participants