PlatformLab / NanoLog

Nanolog is an extremely performant nanosecond scale logging system for C++ that exposes a simple printf-like API.
Other
3k stars 343 forks source link

Memory leak in NanoLog? #68

Closed dreamofboy closed 1 year ago

dreamofboy commented 1 year ago

I built C++ 17 NanoLog static library from the latest source code and linked it to my application. C++ Address Sanitizer is used also. When my program exited, the sanitizer report indicates there is a memory leak.

==18544==ERROR: LeakSanitizer: detected memory leaks

Direct leak of 1073741824 byte(s) in 1 object(s) allocated from:
    #0 0x7f0f8da7f747 in malloc (/usr/lib64/libasan.so.6+0xb4747)
    #1 0x409b6e in NanoLogInternal::Log::Decoder::Decoder() /app/NanoLog/runtime/Log.cc:620

Direct leak of 1048640 byte(s) in 1 object(s) allocated from:
    #0 0x7f0f8da810a7 in operator new(unsigned long) (/usr/lib64/libasan.so.6+0xb60a7)
    #1 0x409cd3 in NanoLogInternal::Log::Decoder::allocateBufferFragment() /app/NanoLog/runtime/Log.cc:1138
    #2 0x409cd3 in NanoLogInternal::Log::Decoder::allocateBufferFragment() /app/NanoLog/runtime/Log.cc:1130
    #3 0x409cd3 in NanoLogInternal::Log::Decoder::Decoder() /app/NanoLog/runtime/Log.cc:631

SUMMARY: AddressSanitizer: 1074790464 byte(s) leaked in 2 allocation(s).

Here is the piece of code about NanoLog in my program.

    NanoLog::setLogFile("./logs/logFile");
    // NanoLog::preallocate();
    NanoLog::setLogLevel(DEBUG);
    ...
    NANO_LOG(ERROR, "Something Failed!");

Is it a bug in Nanolog or I have misused NanoLog? Thanks.