From 9b83d57a7d17050d8cd671c19df99d58239a7707 Mon Sep 17 00:00:00 2001
From: Christophe Geuzaine <cgeuzaine@ulg.ac.be>
Date: Mon, 18 Nov 2013 10:17:10 +0000
Subject: [PATCH] Trying to delete the subclients in the event loop, to prevent
 leaving sockets open.

The old mechanism would lead to resource starvation when creating many subclients (e.g. in a loop).

Please report any issues with subclients -- this is quite a big change :-)
---
 Fltk/onelabGroup.cpp | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/Fltk/onelabGroup.cpp b/Fltk/onelabGroup.cpp
index a223d9dca8..90fd33354b 100644
--- a/Fltk/onelabGroup.cpp
+++ b/Fltk/onelabGroup.cpp
@@ -454,7 +454,19 @@ bool gmshLocalNetworkClient::run()
           stop = true;
           break;
         }
-        else{ // this subclient is not active anymore: pass to the next client
+        else{
+          // this subclient is not active anymore: shut down its server, delete
+          // the server and the client, and go to the next client
+          Msg::Debug("Deleting subclient `%s'", c->getName().c_str());
+          GmshServer *s = c->getGmshServer();
+          c->setGmshServer(0);
+          c->setFather(0);
+          if(s){
+            s->Shutdown();
+            delete s;
+          }
+          removeClient(c);
+          delete c;
           continue;
         }
       }
-- 
GitLab