[mpich2-commits] r5626 - mpich2/trunk/src/binding/cxx

goodell at mcs.anl.gov goodell at mcs.anl.gov
Thu Oct 29 16:57:02 CDT 2009


Author: goodell
Date: 2009-10-29 16:57:02 -0500 (Thu, 29 Oct 2009)
New Revision: 5626

Modified:
   mpich2/trunk/src/binding/cxx/buildiface
Log:
Fix errhandler leak in C++ introduced in r850.

The fix so that MPI::ERRORS_THROW_EXCEPTIONS actually throws (r850)
caused us to leak errhandlers in C++ when using Call_errhandler because
Get_errhandler (correctly) adds a reference to the errhandler that must
be released by calling Errhandler::Free.

Reviewed by robl at .

Modified: mpich2/trunk/src/binding/cxx/buildiface
===================================================================
--- mpich2/trunk/src/binding/cxx/buildiface	2009-10-29 21:57:00 UTC (rev 5625)
+++ mpich2/trunk/src/binding/cxx/buildiface	2009-10-29 21:57:02 UTC (rev 5626)
@@ -2528,26 +2528,50 @@
 // cover the ERRORS_THROW_EXCEPTIONS case.
 void Comm::Call_errhandler( int errorcode ) const
 {
-    if (Get_errhandler() == ERRORS_THROW_EXCEPTIONS) {
+    // we must free the Errhandler object returned from Get_errhandler because
+    // Get_errhandler adds a reference (the MPI Standard says as though a new
+    // object were created)
+    Errhandler current = Get_errhandler();
+    if (current == ERRORS_THROW_EXCEPTIONS) {
+        current.Free();
         throw Exception(errorcode); // throw by value, catch by reference
     }
+    else {
+        current.Free();
+    }
     MPIX_CALL( MPI_Comm_call_errhandler( (MPI_Comm) the_real_comm, errorcode ));
 }
 
 void Win::Call_errhandler( int errorcode ) const
 {
-    if (Get_errhandler() == ERRORS_THROW_EXCEPTIONS) {
+    // we must free the Errhandler object returned from Get_errhandler because
+    // Get_errhandler adds a reference (the MPI Standard says as though a new
+    // object were created)
+    Errhandler current = Get_errhandler();
+    if (current == ERRORS_THROW_EXCEPTIONS) {
+        current.Free();
         throw Exception(errorcode); // throw by value, catch by reference
     }
+    else {
+        current.Free();
+    }
     MPIX_CALL( MPI_Win_call_errhandler( (MPI_Win) the_real_win, errorcode ));
 }
 
 #ifdef MPI_MODE_RDONLY
 void File::Call_errhandler( int errorcode ) const
 {
-    if (Get_errhandler() == ERRORS_THROW_EXCEPTIONS) {
+    // we must free the Errhandler object returned from Get_errhandler because
+    // Get_errhandler adds a reference (the MPI Standard says as though a new
+    // object were created)
+    Errhandler current = Get_errhandler();
+    if (current == ERRORS_THROW_EXCEPTIONS) {
+        current.Free();
         throw Exception(errorcode); // throw by value, catch by reference
     }
+    else {
+        current.Free();
+    }
     MPIX_CALL( MPI_File_call_errhandler( (MPI_File) the_real_file, errorcode ));
 }
 #endif // IO



More information about the mpich2-commits mailing list