diff --git a/Geo/GModelIO_MED.cpp b/Geo/GModelIO_MED.cpp
index d580cde4e2abe2d25c49ab2f67a8a01191f8b1e4..94bcd45a11c7b6f39744b162657374ee9c8a0a58 100644
--- a/Geo/GModelIO_MED.cpp
+++ b/Geo/GModelIO_MED.cpp
@@ -522,7 +522,8 @@ int GModel::writeMED(const std::string &name, bool saveAll, double scalingFactor
     return 0;
   }
 
-  char *meshName = (char*)getName().c_str();
+  std::string strMeshName = getName();
+  char *meshName = (char*)strMeshName.c_str();
 
   // Gmsh always writes 3D unstructured meshes
 #if (MED_MAJOR_NUM == 3)