From f7e6cb9d26dded3f33e8da18a7b16a7e64cefd5b Mon Sep 17 00:00:00 2001
From: Ben Longbons <b.r.longbons@gmail.com>
Date: Mon, 14 Apr 2014 16:04:57 -0700
Subject: Fix memory violation in delayed close

---
 src/map/clif.cpp   | 6 ++----
 src/mmo/socket.hpp | 2 ++
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/map/clif.cpp b/src/map/clif.cpp
index a7dcb52..ea92d15 100644
--- a/src/map/clif.cpp
+++ b/src/map/clif.cpp
@@ -1098,8 +1098,6 @@ void clif_quitsave(Session *, dumb_ptr<map_session_data> sd)
 static
 void clif_waitclose(TimerData *, tick_t, Session *s)
 {
-    // TODO: what happens if the player disconnects
-    // and someone else connects?
     if (s)
         s->eof = 1;
 }
@@ -1110,10 +1108,10 @@ void clif_waitclose(TimerData *, tick_t, Session *s)
  */
 void clif_setwaitclose(Session *s)
 {
-    Timer(gettick() + std::chrono::seconds(5),
+    s->timed_close = Timer(gettick() + std::chrono::seconds(5),
             std::bind(clif_waitclose, ph::_1, ph::_2,
                 s)
-    ).detach();
+    );
 }
 
 /*==========================================
diff --git a/src/mmo/socket.hpp b/src/mmo/socket.hpp
index 3b411e3..256c08b 100644
--- a/src/mmo/socket.hpp
+++ b/src/mmo/socket.hpp
@@ -61,6 +61,8 @@ struct Session
 
     /// Flag needed since structure must be freed in a server-dependent manner
     bool eof;
+    /// Currently used by clif_setwaitclose
+    Timer timed_close;
 
     /// Since this is a single-threaded application, it can't block
     /// These are the read/write queues
-- 
cgit v1.2.3-70-g09d2