[gnote] Fix crash when synchronizing unsaved note



commit 47dce0adc160b3c838da3d89901d47ec1a425563
Author: Aurimas Äernius <aurisc4 gmail com>
Date:   Fri Mar 9 21:48:27 2012 +0200

    Fix crash when synchronizing unsaved note
    
    A crash because of synchronizing an updated note, that has
    previously been synchronized. Happens if synchronization
    occurs before note save is trigerred, the save is performed
    from synchronization thread without proper lock.
    New method note_save added to avoid repeating code.

 src/synchronization/syncmanager.cpp |   14 ++++++++++----
 src/synchronization/syncmanager.hpp |    1 +
 2 files changed, 11 insertions(+), 4 deletions(-)
---
diff --git a/src/synchronization/syncmanager.cpp b/src/synchronization/syncmanager.cpp
index 25f7040..0e2a2f9 100644
--- a/src/synchronization/syncmanager.cpp
+++ b/src/synchronization/syncmanager.cpp
@@ -384,16 +384,14 @@ namespace sync {
           // This is a new note that has never been synchronized to the server
           // TODO: *OR* this is a note that we lost revision info for!!!
           // TODO: Do the above NOW!!! (don't commit this dummy)
-          gdk_threads_enter();
-          (*iter)->save();
-          gdk_threads_leave();
+          note_save(*iter);
           newOrModifiedNotes.push_back(*iter);
           if(m_sync_ui != 0)
             m_sync_ui->note_synchronized_th((*iter)->get_title(), UPLOAD_NEW);
         }
         else if(m_client->get_revision(*iter) <= m_client->last_synchronized_revision()
                 && (*iter)->metadata_change_date() > m_client->last_sync_date()) {
-          (*iter)->save();
+          note_save(*iter);
           newOrModifiedNotes.push_back(*iter);
           if(m_sync_ui != 0) {
             m_sync_ui->note_synchronized_th((*iter)->get_title(), UPLOAD_MODIFIED);
@@ -838,6 +836,14 @@ namespace sync {
   }
 
 
+  void SyncManager::note_save(const Note::Ptr & note)
+  {
+    gdk_threads_enter();
+    note->save();
+    gdk_threads_leave();
+  }
+
+
   SyncLockInfo::SyncLockInfo()
     : client_id(Preferences::obj().get_schema_settings(Preferences::SCHEMA_SYNC)->get_string(Preferences::SYNC_CLIENT_ID))
     , transaction_id(sharp::uuid().string())
diff --git a/src/synchronization/syncmanager.hpp b/src/synchronization/syncmanager.hpp
index a374c10..19b87dd 100644
--- a/src/synchronization/syncmanager.hpp
+++ b/src/synchronization/syncmanager.hpp
@@ -95,6 +95,7 @@ namespace sync {
     static void on_create_note(GObject*, gpointer, gpointer);
     static void on_update_note(GObject*, gpointer, gpointer, gpointer);
     static void on_delete_note(GObject*, gpointer, gpointer);
+    static void note_save(const Note::Ptr & note);
 
     SyncUI::Ptr m_sync_ui;
     SyncClient::Ptr m_client;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]