Knowledgebase
7.x: Leaks in empty C++ Builder application
Posted by Aleksandr Alekseev on 17 December 2018 11:33

Problem:

I receive leak reports from EurekaLog in a blank empty VCL application.

Reason:

  1. You did not set up your project properly, so EurekaLog's leak checking code is running too early.
  2. You may see technical leaks. See below for an example.

Example (technical leak):

  1. When application exits: RTL enters shutdown cycle inside _cleanup() routine from initexit.c file. This routine will call any registered finalization subroutine (e.g. exit procedure), such as EurekaLog and I/O streams finalization.
  2. C++ RTL will flush opened streams during shutdown (fflush() routine from fflush.c file is called from _exit_streams() finalization routine from streams.c file).
  3. Unfortunately, flushing stream will keep an allocated memory block used for stream locking (lock is allocated from _lock_stream() from streams.c).
  4. This memory block will remain alive, even when other code (including EurekaLog) cleanup (inside cleanup cycle in the _cleanup() routine).
  5. EurekaLog will detect memory block that was allocated, but not freed. EurekaLog will report this block as leak.
  6. Once EurekaLog (and other code) finishes shutdown - RTL will continue to cleanup.
  7. RTL will delete allocated locks by calling _cleanup_handle_locks() and _cleanup_stream_locks() (after _cleanup() routine completes) and terminate the process.

Solution: 

  1. Follow our guidelines for setting up your project for leak reporting. Basically, you need to ensure that EurekaLog's code is initialized first and finalized last. Otherwise, EurekaLog's leak checking code will run when there are unallocated resources. Such resources will be reported as leaks, even though it is finalized later.
  2. Ignore technical leaks. You may try to add such leaks as expected leaks. Or you may try to cleanup such leaks manually before execution of EurekaLog's leaks checking. E.g. calling routines such as _cleanup_stream_locks() at shutdown. But this may not always be possible.

See also:


Help Desk Software by Kayako Resolve