Fixed key pair loading crash with SILC Plugin when key pair
[silc.git] / apps / irssi / src / silc / core / silc-core.c
index 3084f7407760da9fe1c0c73b154f7c109dd7d322..07385ed41ee3587312318ac2fc87e9520676ef7f 100644 (file)
@@ -51,6 +51,7 @@ static int init_failed = 0;
 #endif
 
 static int idletag = -1;
+static int running = 0;
 
 /* SILC Client */
 SilcClient silc_client = NULL;
@@ -561,6 +562,7 @@ silc_stopped(SilcClient client, void *context)
 static void
 silc_running(SilcClient client, void *context)
 {
+  running = 1;
   SILC_LOG_DEBUG(("Client library is running"));
 }
 
@@ -791,11 +793,12 @@ void silc_core_deinit(void)
   if (idletag != -1)
     g_source_remove(idletag);
 
-  int stopped = 0;
-  silc_client_stop(silc_client, silc_stopped, &stopped);
-
-  while (!stopped)
-    silc_client_run_one(silc_client);
+  if (running) {
+    int stopped = 0;
+    silc_client_stop(silc_client, silc_stopped, &stopped);
+    while (!stopped)
+      silc_client_run_one(silc_client);
+  }
 
   if (opt_hostname)
     silc_free(opt_hostname);
@@ -823,7 +826,9 @@ void silc_core_deinit(void)
 
   chat_protocol_unregister("SILC");
 
-  silc_pkcs_public_key_free(irssi_pubkey);
-  silc_pkcs_private_key_free(irssi_privkey);
+  if (irssi_pubkey)
+    silc_pkcs_public_key_free(irssi_pubkey);
+  if (irssi_privkey)
+    silc_pkcs_private_key_free(irssi_privkey);
   silc_client_free(silc_client);
 }