Skip to content

Conversation

@ligurio
Copy link
Owner

@ligurio ligurio commented Oct 14, 2025

Fixes #52

@ligurio ligurio force-pushed the ligurio/gh-52-fix-fdp-memleak branch from 66c1af6 to ff80f13 Compare October 15, 2025 13:25
@ligurio ligurio force-pushed the ligurio/gh-52-fix-fdp-memleak branch 4 times, most recently from 03db774 to b1d84fc Compare November 10, 2025 08:25
When luzer runs a test with broken dictionary it runs
`LLVMFuzzerRunDriver()` that prints an error message:

ParseDictionaryFile: error in line 1
		"\\200\\000" # Uses: 283

the it frees argv[] and returns. A function `free_argv()` frees
argv[] again and we observe a segmentation fault. The problem
was fixed by the previous commit. The patch adds an additional
test for the problem.

Follows up #52
Closes #65
@ligurio ligurio force-pushed the ligurio/gh-52-fix-fdp-memleak branch from 3b09aa9 to 9a6f771 Compare November 10, 2025 08:31
@ligurio ligurio requested a review from Buristan November 10, 2025 08:33
Copy link
Collaborator

@Buristan Buristan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sergey,
Thanks for the patch!
I suppose the next commit may be squashed into this one as well.

Please consider my comment below.

LUA_SETHOOK(L, debug_hook, 0, 0);

/* Prevents memory leaks on module exit. */
lua_gc(L, LUA_GCCOLLECT, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose we have several smoking guns here:

  • Since Lua (and therefore LuaJIT) has the GC-based memory management model, it may accumulate memory between iterations of state mutations in the TestOneInput. Libfuzzer checks the possible leaks during fuzzing between state mutations. Hence, we should add -detect_leaks=0 (see options) to the fuzzer options to be sure that we don't fail valid runs due to these false positives. This option disables only intermediate checks. The shutdown check is still enabled (but it may be ignored if you specify the environment variable LSAN_OPTIONS). Adding of lua_gc(), may not be so helpful if the object is allocated once at the first call (loading library via require) and cleared on the exit.
  • Even with the aforementioned option the lua_close() isn't called since the process is finished by the atexit handler, which is set in the FuzzerDriver(). So, we will observe leaks of the FDP object allocated via new.

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also https://github.com/google/atheris/blob/master/native_extension_fuzzing.md#leak-detection

Leak detection
Python is known to leak certain data, such as at interpreter initialization time. You should disable leak detection, for example with -detect_leaks=0.

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.

Memory leak in FDP

3 participants