wsd/DocumentBroker.cpp |   19 +++++++++----------
 1 file changed, 9 insertions(+), 10 deletions(-)

New commits:
commit a8b8ca067acd888ad5376fca497862e595f795a2
Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
Date:   Thu Apr 20 00:10:30 2017 -0400

    wsd: stop the DocBroker when saving session is last
    
    When a session is disconnecting and we use it to save
    (because the other sessions are not viable for saving),
    then we need to correctly detect if by the time
    saving is done there are no other sessions left.
    
    Otherwise, we end up thinking there are other sessions
    when the others had been disconnected during saving.
    
    Change-Id: I55687376f5237a495ae163b53f51ee1d2414d770
    Reviewed-on: https://gerrit.libreoffice.org/36711
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>
    (cherry picked from commit 2a0253b76be3e329af55d0ab80157544eea2253e)
    Reviewed-on: https://gerrit.libreoffice.org/36714
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Tested-by: Jan Holesovsky <ke...@collabora.com>

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 94a49a1d..1afd30f0 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -562,16 +562,13 @@ bool DocumentBroker::saveToStorage(const std::string& 
sessionId,
 
     const bool res = saveToStorageInternal(sessionId, success, result);
 
+    // We've saved and can safely destroy this session.
+    removeSessionInternal(sessionId);
+
     // If marked to destroy, then this was the last session.
-    // FIXME: If during that last save another client connects
-    // to this doc, the _markToDestroy will be reset and we
-    // will leak the last session. Need to mark the session as
-    // dead and cleanup somehow.
-    if (_markToDestroy)
+    // Otherwise, check that we are (which we might be by now).
+    if (_markToDestroy || _sessions.empty())
     {
-        // We've saved and can safely destroy.
-        removeSessionInternal(sessionId);
-
         // Stop so we get cleaned up and removed.
         _stop = true;
     }
@@ -866,7 +863,8 @@ size_t DocumentBroker::removeSession(const std::string& id, 
bool destroyIfLast)
     try
     {
         LOG_INF("Removing session [" << id << "] on docKey [" << _docKey <<
-                "]. Have " << _sessions.size() << " sessions.");
+                "]. Have " << _sessions.size() << " sessions. markToDestroy: " 
<< _markToDestroy <<
+                ", LastEditableSession: " << _lastEditableSession);
 
         if (!_lastEditableSession || !autoSave(true))
             return removeSessionInternal(id);
@@ -1230,7 +1228,8 @@ void DocumentBroker::destroyIfLastEditor(const 
std::string& id)
     // Last view going away, can destroy.
     _markToDestroy = (_sessions.size() <= 1);
     LOG_DBG("startDestroy on session [" << id << "] on docKey [" << _docKey <<
-            "], markToDestroy: " << _markToDestroy << ", lastEditableSession: 
" << _lastEditableSession);
+            "], sessions: " << _sessions.size() << " markToDestroy: " << 
_markToDestroy <<
+            ", lastEditableSession: " << _lastEditableSession);
 }
 
 void DocumentBroker::setModified(const bool value)
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to