Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fixed bug in SMPI datatypes, causing SG to segfault.
authorChristian Heinrich <christian.heinrich@livando.com>
Mon, 16 Mar 2015 16:28:22 +0000 (17:28 +0100)
committerChristian Heinrich <franz-christian.heinrich@inria.fr>
Thu, 4 Jun 2015 12:41:13 +0000 (14:41 +0200)
- For pre-defined datatypes such as MPI_INT, the 'in_use' counter of
  that datatype was able to obtain negative values in certain cases.

  This caused SimGrid to crash with a segfault, for instance when
  running fupermod.

This bug was reported by Tania Malik on
the 24th of February on the SG Mailing list.

src/smpi/smpi_mpi_dt.c

index 4692a2b..8746df9 100644 (file)
@@ -23,30 +23,32 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi_dt, smpi,
 xbt_dict_t smpi_type_keyvals = NULL;
 int type_keyval_id=0;//avoid collisions
 
-#define CREATE_MPI_DATATYPE(name, type)       \
-  static s_smpi_mpi_datatype_t mpi_##name = { \
+#define CREATE_MPI_DATATYPE(name, type)               \
+  static s_smpi_mpi_datatype_t mpi_##name = {         \
     (char*) # name,                                   \
-    sizeof(type),  /* size */                 \
-    0,             /*was 1 has_subtype*/             \
-    0,             /* lb */                   \
-    sizeof(type),  /* ub = lb + size */       \
-    DT_FLAG_BASIC,  /* flags */              \
-    NULL,           /* attributes */         \
-    NULL,           /* pointer on extended struct*/ \
-  };                                          \
+    sizeof(type),   /* size */                        \
+    0,              /*was 1 has_subtype*/             \
+    0,              /* lb */                          \
+    sizeof(type),   /* ub = lb + size */              \
+    DT_FLAG_BASIC,  /* flags */                       \
+    NULL,           /* attributes */                  \
+    NULL,           /* pointer on extended struct*/   \
+    0               /* in_use counter */              \
+  };                                                  \
 MPI_Datatype name = &mpi_##name;
 
-#define CREATE_MPI_DATATYPE_NULL(name)       \
-  static s_smpi_mpi_datatype_t mpi_##name = { \
+#define CREATE_MPI_DATATYPE_NULL(name)                \
+  static s_smpi_mpi_datatype_t mpi_##name = {         \
     (char*) # name,                                   \
-    0,  /* size */                 \
-    0,             /*was 1 has_subtype*/             \
-    0,             /* lb */                   \
-    0,  /* ub = lb + size */       \
-    DT_FLAG_BASIC,  /* flags */              \
-    NULL,           /* attributes */         \
-    NULL           /* pointer on extended struct*/ \
-  };                                          \
+    0,              /* size */                        \
+    0,              /* was 1 has_subtype*/            \
+    0,              /* lb */                          \
+    0,              /* ub = lb + size */              \
+    DT_FLAG_BASIC,  /* flags */                       \
+    NULL,           /* attributes */                  \
+    NULL,           /* pointer on extended struct*/   \
+    0               /* in_use counter */              \
+  };                                                  \
 MPI_Datatype name = &mpi_##name;
 
 //The following are datatypes for the MPI functions MPI_MAXLOC and MPI_MINLOC.
@@ -446,7 +448,10 @@ void smpi_datatype_use(MPI_Datatype type){
 
 
 void smpi_datatype_unuse(MPI_Datatype type){
-  if(type && type->in_use-- == 0 && (type->flags & DT_FLAG_DESTROYED))
+  if (type->in_use > 0)
+    type->in_use--;
+
+  if(type && type->in_use == 0 && (type->flags & DT_FLAG_DESTROYED))
     smpi_datatype_free(&type);
 
 #ifdef HAVE_MC