Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix potential mem leak seen by scan-build.
[simgrid.git] / src / smpi / mpi / smpi_errhandler.cpp
index bb19ffc..74e2242 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2007-2020. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2007-2021. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
@@ -8,10 +8,8 @@
 
 #include <cstdio>
 
-simgrid::smpi::Errhandler mpi_MPI_ERRORS_RETURN;
-MPI_Errhandler MPI_ERRORS_RETURN=&mpi_MPI_ERRORS_RETURN;
-simgrid::smpi::Errhandler mpi_MPI_ERRORS_ARE_FATAL;
-MPI_Errhandler MPI_ERRORS_ARE_FATAL=&mpi_MPI_ERRORS_ARE_FATAL;
+simgrid::smpi::Errhandler smpi_MPI_ERRORS_RETURN;
+simgrid::smpi::Errhandler smpi_MPI_ERRORS_ARE_FATAL;
 
 namespace simgrid{
 namespace smpi{
@@ -45,11 +43,15 @@ void Errhandler::ref()
 }
 
 void Errhandler::unref(Errhandler* errhandler){
+  if(errhandler == MPI_ERRORS_ARE_FATAL || errhandler == MPI_ERRORS_RETURN)
+    return;
   errhandler->refcount_--;
   if(errhandler->refcount_==0){
+    F2C::free_f(errhandler->f2c_id());
     delete errhandler;
   }
 }
 
 }
+
 }