0

Below is my program snippet. I haven't return full code but code is working fine.

class Sig 
{
 public:
 pthread_t tid;
 Sig()
 {
  pthread_create(&tid,NULL,signal_function,NULL);
 }

 ~Sig()
 {
   int r = pthread_detach(tid);
   if ( r !=0 ) {
    assert(0);
   }
 }

}

void signal_function(void *arg0)
{
  for (; ;) {
  // Wait until signal handler called. 
  int ret = pause();
  // Signal came do some work and return
  }
}

int main()
{ 
   Sig sig;
   return 0;
}

Valgrind is showing this as definite leak and I think the problem is whenever my program exit without sending signal pause is not releasing resource.

Is there alternative to pause where it will return when the program exit ? or any other solution or you see any bug in the above program.

Valgrind leak

==12599== 352 bytes in 1 blocks are definitely lost in loss record 169 of 315
==12599==    at 0x4C27F94: calloc (vg_replace_malloc.c:279)
==12599==    by 0x401128E: _dl_allocate_tls (in /lib64/ld-2.3.4.so)
==12599==    by 0x76284ED: pthread_create@@GLIBC_2.2.5 (in /lib64/tls/libpthr
ead-2.3.4.so)
==12599==    by 0xA69082: Sig::Sig() (sim_main.cc:18)
==12599==    by 0xA6B1A5: main (sim_main.cc:34)
Kninnug
  • 7,992
  • 1
  • 30
  • 42
eswaat
  • 733
  • 1
  • 13
  • 31

0 Answers0