Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

Memory leak in parallel_reduce

Darcy_Harrison
Beginner
256 Views

Class finish_reduce that has_right_zombie will not call the destructor of the contained body object if the join operation throws.

From parallel_reduce.h:

[cpp]if( has_right_zombie ) {
   // Right child was stolen.
   Body* s = zombie_space.begin();
   my_body->join( *s );
   s->~Body();
}[/cpp]

Clearly s->~Body() will not be called when my_body->join( *s ) throws. I propose:

[cpp]if( has_right_zombie ) {

   // Right child was stolen.
   Body* s = zombie_space.begin();
   try{
      my_body->join( *s );
      s->~Body();
   }catch(...){
      s->~Body();
      throw;
   }
}[/cpp]

0 Kudos
1 Reply
Darcy_Harrison
Beginner
256 Views

Actually, I remembered that I had submitted essentially the same bug but with respect to cancellation. The solution proposed here: http://software.intel.com/en-us/forums/topic/329081 is better.

0 Kudos
Reply