Index: camel/providers/groupwise/camel-groupwise-folder.c =================================================================== --- camel/providers/groupwise/camel-groupwise-folder.c.orig +++ camel/providers/groupwise/camel-groupwise-folder.c @@ -862,16 +862,27 @@ update_update (CamelSession *session, Ca struct _folder_update_msg *m = (struct _folder_update_msg *)msg; EGwConnectionStatus status; CamelException *ex = NULL; + CamelGroupwiseStore *gw_store = CAMEL_GROUPWISE_STORE (m->folder->parent_store); GList *item_list, *items_full_list = NULL, *last_element=NULL; int cursor = 0; const char *position = E_GW_CURSOR_POSITION_END; gboolean done; + /* Hold the connect_lock. + In case if user went offline, don't do anything. + m->cnc would have become invalid, as the store disconnect unrefs it. + */ + CAMEL_SERVICE_REC_LOCK (gw_store, connect_lock); + if (((CamelOfflineStore *) gw_store)->state == CAMEL_OFFLINE_STORE_NETWORK_UNAVAIL || + ((CamelService *)gw_store)->status == CAMEL_SERVICE_DISCONNECTED) { + goto end1; + } + status = e_gw_connection_create_cursor (m->cnc, m->container_id, "id", NULL, &cursor); if (status != E_GW_CONNECTION_STATUS_OK) { g_warning ("ERROR update update\n"); - return ; + goto end1; } done = FALSE; @@ -883,7 +894,7 @@ update_update (CamelSession *session, Ca if (status != E_GW_CONNECTION_STATUS_OK) { g_warning ("ERROR update update\n"); e_gw_connection_destroy_cursor (m->cnc, m->container_id, cursor); - return; + goto end1; } if (!item_list || g_list_length (item_list) == 0) @@ -906,6 +917,7 @@ update_update (CamelSession *session, Ca } e_gw_connection_destroy_cursor (m->cnc, m->container_id, cursor); + CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); /* Take out only the first part in the list until the @ since it is guaranteed to be unique only until that symbol */ @@ -927,6 +939,11 @@ update_update (CamelSession *session, Ca g_print ("\nNumber of items in the folder: %d \n", g_list_length(items_full_list)); gw_update_all_items (m->folder, items_full_list, ex); + + return; + end1: + CAMEL_SERVICE_REC_UNLOCK (gw_store, connect_lock); + return; } static void