Do not allow stopping client library before it has been started.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 24 May 2007 12:33:29 +0000 (12:33 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 24 May 2007 12:33:29 +0000 (12:33 +0000)
Fixed channel and entry deleting.

lib/silcclient/client.c
lib/silcclient/client_entry.c

index ab13fd6d9fea4963b88eeeaeebb528f46c18fa38..d7942f5f0525d9a336f2933081ab7ba7e36bf560 100644 (file)
@@ -1099,6 +1099,12 @@ void silc_client_stop(SilcClient client, SilcClientStopped stopped,
 {
   SILC_LOG_DEBUG(("Stopping client"));
 
+  if (!silc_fsm_is_started(&client->internal->fsm)) {
+    SILC_LOG_WARNING(("Attempting to stop client library before it has been "
+                     "started (silc_client_init not called)"));
+    return;
+  }
+
   client->internal->running = (SilcClientRunning)stopped;
   client->internal->running_context = context;
 
index c59a48fd3e4992008c26ed4a53cea0323688f2b5..a6dc88d578946a133a49320a97725dc94166ed9a 100644 (file)
@@ -1622,9 +1622,10 @@ SilcBool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
                                 SilcChannelEntry channel)
 {
   SilcIDCacheEntry id_cache;
-  SilcBool ret;
+  SilcBool ret = TRUE;
   SilcCipher key;
   SilcHmac hmac;
+  char *namec;
 
   if (!channel)
     return FALSE;
@@ -1636,10 +1637,12 @@ SilcBool silc_client_del_channel(SilcClient client, SilcClientConnection conn,
 
   silc_mutex_lock(conn->internal->lock);
   if (silc_idcache_find_by_context(conn->internal->channel_cache, channel,
-                                  &id_cache))
-    silc_free(id_cache->name);
-  ret = silc_idcache_del_by_context(conn->internal->channel_cache,
-                                   channel, NULL);
+                                  &id_cache)) {
+    namec = id_cache->name;
+    ret = silc_idcache_del_by_context(conn->internal->channel_cache,
+                                     channel, NULL);
+    silc_free(namec);
+  }
   silc_mutex_unlock(conn->internal->lock);
 
   if (!ret)
@@ -2029,7 +2032,8 @@ SilcBool silc_client_del_server(SilcClient client, SilcClientConnection conn,
                                SilcServerEntry server)
 {
   SilcIDCacheEntry id_cache;
-  SilcBool ret;
+  SilcBool ret = TRUE;
+  char *namec;
 
   if (!server)
     return FALSE;
@@ -2041,10 +2045,12 @@ SilcBool silc_client_del_server(SilcClient client, SilcClientConnection conn,
 
   silc_mutex_lock(conn->internal->lock);
   if (silc_idcache_find_by_context(conn->internal->server_cache, server,
-                                  &id_cache))
-    silc_free(id_cache->name);
-  ret = silc_idcache_del_by_context(conn->internal->server_cache,
-                                   server, NULL);
+                                  &id_cache)) {
+    namec = id_cache->name;
+    ret = silc_idcache_del_by_context(conn->internal->server_cache,
+                                     server, NULL);
+    silc_free(namec);
+  }
   silc_mutex_unlock(conn->internal->lock);
 
   silc_free(server->server_name);