0

I have several "possibly lost" memory leak issues in Valgrind and am wondering if I am doing something wrong with cleaning up the POSIX timers.

In the following code I create the timers:

void LicensingTimer::activate_timer(){
    sigevent timer_signal_event;
    timer_signal_event.sigev_notify = SIGEV_THREAD;
    timer_signal_event.sigev_value.sival_ptr = (void *) this;
    timer_signal_event.sigev_notify_function = &LicensingTimer::handle_wrapper;
    timer_signal_event.sigev_notify_attributes = NULL;
    timer_create(CLOCK_MONOTONIC, &timer_signal_event, &timer);

    timer_period.it_value.tv_sec = 1;
    timer_period.it_interval.tv_sec = 1;

    timer_settime(timer, 0, &timer_period, NULL);
}

In the destructor the timer is cleaned up:

LicensingTimer::~LicensingTimer(){
    timer_delete(timer);
}

However using Valgrind I am getting the following error:

==88303== 304 bytes in 1 blocks are possibly lost in loss record 1 of 1
==88303==    at 0x483DD99: calloc (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==88303==    by 0x40149CA: allocate_dtv (dl-tls.c:286)
==88303==    by 0x40149CA: _dl_allocate_tls (dl-tls.c:532)
==88303==    by 0x502D322: allocate_stack (allocatestack.c:622)
==88303==    by 0x502D322: pthread_create@@GLIBC_2.2.5 (pthread_create.c:660)
==88303==    by 0x4861BCC: __start_helper_thread (timer_routines.c:176)
==88303==    by 0x503547E: __pthread_once_slow (pthread_once.c:116)
==88303==    by 0x48609A2: timer_create@@GLIBC_2.3.3 (timer_create.c:101)
==88303==    by 0x1209C9: LicensingTimer::activate_timer() (timer.cpp:44)
==88303==    by 0x156B5B: LicensingClient::main_process() (client.cpp:242)
==88303==    by 0x15CC46: main (main.cpp:24)

I did find several posts where people say it is a Valgrind bug:

However these posts are of many years ago.

Am I doing something wrong in cleaning up the timers or is there something with Valgrind and the timer_create() function?

  • 2
    How is `LicensingTimer` used, and does it follow the Rule of Three? Please create a [mcve] – alter_igel Jun 09 '21 at 14:59
  • 1
    https://stackoverflow.com/questions/54435972/pthread-created-followed-by-pthread-join-valgrind-possible-loss-c https://sourceware.org/bugzilla/show_bug.cgi?id=3087 – KamilCuk Jun 09 '21 at 15:32

0 Answers0