diff --git a/Geo/GModelIO_MSH2.cpp b/Geo/GModelIO_MSH2.cpp
index 3725973cb52f4fd5e9ff860e0bb8eebc2c34806b..007f883f80494e2cf88e706feb3160643bd6b321 100644
--- a/Geo/GModelIO_MSH2.cpp
+++ b/Geo/GModelIO_MSH2.cpp
@@ -704,7 +704,9 @@ int GModel::_readMSH2(const std::string &name)
       if(!fgets(str, sizeof(str), fp) || feof(fp))
         break;
     }
-    
+    if(feof(fp))
+      break;
+
     if(!strncmp(&str[1], "Periodic",8)) {
       readMSHPeriodicNodes(fp,this);
       break;
@@ -714,7 +716,7 @@ int GModel::_readMSH2(const std::string &name)
         break;
     } while(str[0] != '$');
   }
-  
+
   fclose(fp);
 
   return postpro ? 2 : 1;