Memory leak fixes.
[silc.git] / apps / irssi / src / silc / core / silc-core.c
index 8c38c5c7130c294b96197e8aee2671649ac52bd4..259d7a6f8698fd665e988d68b61c64a9d1a99cc8 100644 (file)
@@ -292,8 +292,8 @@ void silc_opt_callback(poptContext con,
   }
 
   if (strcmp(opt->longName, "hostname") == 0) {
-    g_free(opt_hostname);
-    opt_hostname = g_strdup(arg);
+    silc_free(opt_hostname);
+    opt_hostname = strdup(arg);
   }
 
   if (strcmp(opt->longName, "list-ciphers") == 0) {
@@ -372,6 +372,8 @@ silc_stopped(SilcClient client, void *context)
   SILC_LOG_DEBUG(("Client library has stopped"));
   if (idletag != -1)
     g_source_remove(idletag);
+  signal_emit("chat protocol deinit", 1,
+             chat_protocol_find("SILC"));
 }
 
 static void sig_gui_quit(SILC_SERVER_REC *server, const char *msg)
@@ -404,9 +406,10 @@ static void sig_init_finished(void)
   }
 
   /* Initialize the SILC client */
+  opt_hostname = (opt_hostname ? opt_hostname : silc_net_localhost());
   if (!silc_client_init(silc_client, settings_get_str("user_name"),
-                       opt_hostname ? opt_hostname : silc_net_localhost(),
-                       settings_get_str("real_name"), silc_running, NULL)) {
+                       opt_hostname, settings_get_str("real_name"),
+                       silc_running, NULL)) {
     sleep(1);
     exit(1);
     return;
@@ -564,12 +567,17 @@ void silc_core_deinit(void)
   if (idletag != -1)
     g_source_remove(idletag);
 
-  signal_emit("chat protocol deinit", 1,
-       chat_protocol_find("SILC"));
+  if (opt_hostname)
+    silc_free(opt_hostname);
+  if (opt_nickname)
+    g_free(opt_nickname);
+
   signal_remove("setup changed", (SIGNAL_FUNC) sig_setup_changed);
   signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
   signal_remove("gui exit", (SIGNAL_FUNC) sig_gui_quit);
 
+  silc_hash_free(sha1hash);
+
   silc_queue_deinit();
   silc_server_deinit();
   silc_channels_deinit();
@@ -580,7 +588,7 @@ void silc_core_deinit(void)
 
   chat_protocol_unregister("SILC");
 
-  silc_pkcs_private_key_free(irssi_privkey);
   silc_pkcs_public_key_free(irssi_pubkey);
+  silc_pkcs_private_key_free(irssi_privkey);
   silc_client_free(silc_client);
 }