#
# pan/usenet-utils/blowfish.h does a #define DWORD
# This breaks queue.h which uses typedef DWORD
# Move inclusion of queue.h up to avoid the conflict.
#
diff --git a/pan/data-impl/data-impl.h b/pan/data-impl/data-impl.h
index 5859bd6..9f8faa6 100644
--- a/pan/data-impl/data-impl.h
+++ b/pan/data-impl/data-impl.h
@@ -27,6 +27,7 @@
 #include <vector>
 #include <deque>
 
+#include <pan/tasks/queue.h>
 #include <pan/general/quark.h>
 #include <pan/general/macros.h>
 #include <pan/general/map-vector.h>
@@ -38,7 +39,7 @@
 #include <pan/data/article-cache.h>
 #include <pan/data/encode-cache.h>
 #include <pan/data/data.h>
-#include <pan/tasks/queue.h>
+
 #include <pan/data-impl/data-io.h>
 #include <pan/data-impl/article-filter.h>
 #include <pan/data-impl/rules-filter.h>




#
# rename is specified as NOT overwriting an existing file, so
# do a remove before a rename. This is OS dependent, so #ifdef the change
#
diff --git a/pan/data-impl/data-io.cc b/pan/data-impl/data-io.cc
index 56127bf..d7dc8f9 100644
--- a/pan/data-impl/data-io.cc
+++ b/pan/data-impl/data-io.cc
@@ -202,7 +202,9 @@ namespace
 
     const std::string tmpfile (filename + ".tmp");
     if (ok) {
-//      ::remove (filename.c_str()); not needed
+#if defined(G_OS_WIN32)
+      ::remove (filename.c_str()); // Needed by Win32
+#endif
       if (rename (tmpfile.c_str(), filename.c_str()))
         std::cerr << LINE_ID << " ERROR renaming from [" << tmpfile << "] to [" << filename << "]: " << g_strerror(errno) << '\n';
       if (chmod (filename.c_str(), 0600))


#
# This can still crash, but this is LOTS better
# Probably a thread issue, perhaps we are destroying
# data used by another thread?
#
diff --git a/pan/data/cert-store.cc b/pan/data/cert-store.cc
index 7bd92cd..65ee25e 100644
--- a/pan/data/cert-store.cc
+++ b/pan/data/cert-store.cc
@@ -340,7 +340,8 @@ namespace pan
   {
     gnutls_certificate_free_credentials (_creds);
     foreach (certs_m, _cert_to_server, it)
-      gnutls_x509_crt_deinit(it->second);
+      if (it->second)
+        gnutls_x509_crt_deinit(it->second);
   }
 
 

#
# Make sure the saved "port" value is what is displayed
# when doing an edit.
#
diff --git a/pan/gui/server-ui.cc b/pan/gui/server-ui.cc
index e0d9c8b..4c32098 100644
--- a/pan/gui/server-ui.cc
+++ b/pan/gui/server-ui.cc
@@ -131,7 +131,6 @@ namespace
     }
 
     pan_entry_set_text (d->address_entry, addr);
-    pan_spin_button_set (d->port_spin, port);
     pan_spin_button_set (d->connection_limit_spin, max_conn);
     pan_entry_set_text (d->auth_username_entry, user);
     pan_entry_set_text (d->auth_password_entry, pass);
@@ -177,6 +176,8 @@ namespace
 
     gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(d->always_trust_checkbox), trust);
 #endif
+
+    pan_spin_button_set (d->port_spin, port);
   }
 
   void



#
# Do not refer to chan or _channel after it has been deinitialised or freed!
#
# Comment out some unused variables.
#
diff --git a/pan/tasks/socket-impl-openssl.cc b/pan/tasks/socket-impl-openssl.cc
index f7035c9..bb0135d 100644
--- a/pan/tasks/socket-impl-openssl.cc
+++ b/pan/tasks/socket-impl-openssl.cc
@@ -305,11 +305,11 @@ namespace
   {
     GIOGnuTLSChannel *chan = (GIOGnuTLSChannel *)handle;
     g_io_channel_unref(chan->giochan);
+    // free callback struct
+    delete (mydata_t*)gnutls_session_get_ptr (chan->session);
     gnutls_deinit (chan->session);
     g_free(chan->host);
     g_free(chan);
-    // free callback struct
-    delete (mydata_t*)gnutls_session_get_ptr (chan->session);
   }
 }
 
@@ -325,10 +325,10 @@ GIOChannelSocketGnuTLS :: ~GIOChannelSocketGnuTLS ()
 
   if (_channel)
   {
-    GIOGnuTLSChannel *chan = (GIOGnuTLSChannel *)_channel;
+//    GIOGnuTLSChannel *chan = (GIOGnuTLSChannel *)_channel;
     g_io_channel_shutdown (_channel, true, 0);
-    _gnutls_free(_channel);
     g_string_free(_channel->read_buf,true);
+    _gnutls_free(_channel);
     _channel = 0;
   }
 
@@ -375,7 +375,8 @@ namespace
 
   static void set_blocking(gnutls_session_t& session, bool val)
   {
-    int fd(-1), flags;
+//    int fd(-1), flags;
+    int fd(-1);
     gnutls_transport_ptr_t tmp = gnutls_transport_get_ptr (session);
     fd = GPOINTER_TO_INT (tmp);
 
@@ -601,7 +602,7 @@ GIOChannelSocketGnuTLS :: do_read ()
 
   bool more (true);
 
-  GIOGnuTLSChannel * chan = (GIOGnuTLSChannel*)_channel;
+//  GIOGnuTLSChannel * chan = (GIOGnuTLSChannel*)_channel;
 
   while (more && !_abort_flag)
   {
@@ -787,7 +788,8 @@ GIOChannelSocketGnuTLS :: gnutls_get_iochannel(GIOChannel* channel, const char*
 
 	GIOGnuTLSChannel *chan(0);
 	GIOChannel *gchan(0);
-	int err(0), fd(0);
+//	int err(0), fd(0);
+	int fd(0);
 
 	chan = g_new0(GIOGnuTLSChannel, 1);
 	g_return_val_if_fail(chan, 0);
@@ -820,7 +822,7 @@ GIOChannelSocketGnuTLS :: gnutls_get_iochannel(GIOChannel* channel, const char*
 	g_io_channel_init(gchan);
   gchan->read_buf = g_string_sized_new(4096*128);
 
-  int ret;
+//  int ret;
   set_blocking(session, true);
 
   if (_gnutls_handshake(gchan) == G_IO_STATUS_NORMAL)
