This is an archive of the discontinued LLVM Phabricator instance.

[LSan] New experimental flag for background leak checking before exit.
Needs ReviewPublic

Authored by m.kashkarov on Nov 22 2017, 5:11 AM.

Details

Reviewers
kcc
vitalybuka
Group Reviewers
Restricted Project
Summary

New sanitizer option - leak_check_interval_s:
spawns a background thread at startup which periodically do recoverable leak check with given interval.
Report file names (if log_path option != stderr|stdout) are appended with prefix "in-progress" and for the DoLeakCheck() call at exit - are restores back.

This can be used for leak sanitization long-running processes that never exits.

Diff Detail

Repository
rL LLVM

Event Timeline

m.kashkarov created this revision.Nov 22 2017, 5:11 AM
m.kashkarov edited the summary of this revision. (Show Details)

Add unimplemented in lsan mac version, update standalone lsan.

m.ostapenko added subscribers: llvm-commits, m.ostapenko.

Adding maintainers + some comments.

lib/lsan/lsan_common.cc
767

Why do you need all this stuff? Can't you use separate file descriptor from main report_fd? Because changing report_fd on the fly looks like a bad idea: what will happen if some another thread is reporting concurrently (corrupted reports, I guess)?

lib/lsan/lsan_common.h
155

You don't need to explicitly initialize global variables with 0.

lib/lsan/lsan_interceptors.cc
34

Please don't. Why do you need this at all?

418

Likewise, why do you need this?

m.kashkarov marked 4 inline comments as done.Nov 30 2017, 11:27 AM
m.kashkarov added inline comments.
lib/lsan/lsan_common.cc
767

If it's ok to create another file only for leak detected in the background thread - i can change the current logging behaviour.

lib/lsan/lsan_common.h
155

There is build error error: uninitialized const ‘__lsan::kLeaksIntervalNotSet’ [-fpermissive] when not set to 0

lib/lsan/lsan_interceptors.cc
34

Oh, didn't notice that it was already included here, tested on gcc without #include "sanitizer_common/sanitizer_posix.h".

418

This is for the real_pthread_create used in internal_start_thread.

m.kashkarov marked 4 inline comments as done.

Fixed typo error, update.

m.kashkarov marked an inline comment as not done.
alekseyshl added inline comments.Nov 30 2017, 11:33 AM
lib/asan/asan_rtl.cc
463

FYI, this won't work on Android (see D27003, for example). Same for LSan.

alekseyshl edited edge metadata.Nov 30 2017, 3:17 PM

Can it be implemented with timer_create() instead of the thread?

vitalybuka resigned from this revision.Dec 8 2017, 3:57 PM
m.kashkarov marked an inline comment as done.

Back to this feature, draft with signals impl.

kcc added a comment.Jul 16 2018, 12:50 PM

I'd prefer to not have this functionality in lsan -- it already has __lsan_do_recoverable_leak_check which should be sufficient for a user to implement this functionality on their side.
(If not, that may need to be fixed).