udoprog / checkers

A sanity checker for global allocations in Rust
Apache License 2.0
48 stars 2 forks source link

Add with_muted to selectively disable checkers (relates #5) #6

Closed udoprog closed 4 years ago

kstrafe commented 4 years ago

Isn't there a way to do this globally for all statics in a binary? It's going to be a daunting task to add muting to all dependencies.

udoprog commented 4 years ago

Isn't there a way to do this globally for all statics in a binary? It's going to be a daunting task to add muting to all dependencies.

Not that I know of, but suggestions would be welcome!

lazy_static defines a static pointer which might be possible to identify, but the memory being allocated and pointed to is not special and is initialized the first time the static reference is accessed. It might in turn recursively allocate more memory.

Another alternative is to filter certain events by their allocation pattern to mark them as OK, like this test expects a certain number of memory regions to leak. You'd do this by setting up a user-defined condition.

kstrafe commented 4 years ago

I guess one way to do it is to "initialize" the program, clear the global allocator (or mark allocated regions as DONT_CARE or something along those lines), and then run the actual test...

Maybe #[checkers::test] can run the test twice, the first time is used to set up statics and ignore them, and the second time uses the already set-up statics. If the second iteration replaced the statics, then Drop will be invoked, so all is well.

udoprog commented 4 years ago

Interesting suggestion! There's a number of pitfalls. Let's move the discussion to #5 and I'll at least get this merged for now. This is not a solution, but at least addresses a workable gap in the API.