-
Notifications
You must be signed in to change notification settings - Fork 5
luzer: fix memory leak in FDP #66
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
66c1af6 to
ff80f13
Compare
03db774 to
b1d84fc
Compare
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
3b09aa9 to
9a6f771
Compare
Buristan
left a comment
There was a problem hiding this 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); |
There was a problem hiding this comment.
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 variableLSAN_OPTIONS). Adding oflua_gc(), may not be so helpful if the object is allocated once at the first call (loading library viarequire) 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 theFuzzerDriver(). So, we will observe leaks of the FDP object allocated vianew.
There was a problem hiding this comment.
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.
Fixes #52