slog icon indicating copy to clipboard operation
slog copied to clipboard

memory leak in slog_scope

Open mimoo opened this issue 4 years ago • 1 comments

Running valgrind on a program I have, I obtain a lot of these:

==4175714== 16 bytes in 1 blocks are possibly lost in loss record 24 of 103
==4175714==    at 0x4C29DAF: malloc (vg_replace_malloc.c:309)
==4175714==    by 0x1198DEB: alloc::alloc::alloc (alloc.rs:81)
==4175714==    by 0x1198D5B: alloc::alloc::exchange_malloc (alloc.rs:203)
==4175714==    by 0x119783C: alloc::sync::Arc<T>::new (sync.rs:302)
==4175714==    by 0x11960B6: slog::OwnedKVList::root (lib.rs:3426)
==4175714==    by 0x119618E: slog::Logger<D>::root (lib.rs:1125)
==4175714==    by 0x119433E: __static_ref_initialize (lib.rs:110)
==4175714==    by 0x119433E: core::ops::function::FnOnce::call_once (function.rs:232)
==4175714==    by 0x119271A: lazy_static::lazy::Lazy<T>::get::{{closure}} (inline_lazy.rs:31)
==4175714==    by 0x1198737: std::sync::once::Once::call_once::{{closure}} (once.rs:264)
==4175714==    by 0x1799E70: std::sync::once::Once::call_inner (once.rs:417)
==4175714==    by 0x11986B2: std::sync::once::Once::call_once (once.rs:264)                                                                                              ==4175714==    by 0x119BAA8: get<arc_swap::ArcSwapAny<alloc::sync::Arc<slog::Logger<alloc::sync::Arc<SendSyncRefUnwindSafeDrain>>>, arc_swap::gen_lock::Global>,fn() -> a
rc_swap::ArcSwapAny<alloc::sync::Arc<slog::Logger<alloc::sync::Arc<SendSyncRefUnwindSafeDrain>>>, arc_swap::gen_lock::Global>> (inline_lazy.rs:30)
==4175714==    by 0x119BAA8: __stability (<::lazy_static::__lazy_static_internal macros>:16)
==4175714==    by 0x119BAA8: <slog_scope::GLOBAL_LOGGER as core::ops::deref::Deref>::deref (<::lazy_static::__lazy_static_internal macros>:18)

way to repro:

git clone --depth 1 https://github.com/libra/libra.git
cd libra/testsuite/libra-fuzzer
mkdir -p fuzz/corpus/addmission_control
echo "CswBKskB0njtjZhgowd2SjEB3IHegKQ9IUQRjELOcD0Xov3K9CE2F6aKwZmkBwMAAAAZAAAAtlYH3Ag+23KMY6B1tqBHEbBAUaxMScfWwZcOhVJS1/oSHKpxHc03UIdPSvkksDFODSAAAADGx885lPdOFj7vzuiGRP/v4VeM/Vq8GhWEXEPzFwaT8kAAAAB2ovix102nyik07zRXRqYO6/hovSjhn+p2MEyxnWD4hB6CAgHZH3x5JJ1zOjQUt+3Dd5vGHuoE6U7Ft7tBpXsF" | base64 -D > fuzz/corpus/admission_control/0705ebd76487a545fbde086c56f678bc996db1c3
cargo build --bin investigate
valgrind --leak-check=full ../../target/debug/investigate  -i fuzz/corpus/admission_control/0705ebd76487a545fbde086c56f678bc996db1c3

mimoo avatar Feb 14 '20 18:02 mimoo

lazy_static never frees stuff inside it by design. I'm not sure if there's more to it.

dpc avatar Feb 14 '20 19:02 dpc