Mon Jun 18 22:21:37 CEST 2007 Jochen Eisinger <coffee@silcnet.org>
[silc.git] / lib / silcclient / client.c
index e3a0e58dae569f3b926ff52cd5eeffe04d4ae03a..154de47819ff7dcbca86f7051f663dd3af400718 100644 (file)
@@ -1418,6 +1418,7 @@ void silc_client_packet_send(SilcClient client,
   const SilcBufferStruct packet;
   int block_len;
   SilcUInt32 sequence = 0;
+  int src_id_allocated = FALSE;
 
   if (!sock)
     return;
@@ -1461,6 +1462,7 @@ void silc_client_packet_send(SilcClient client,
   } else {
     packetdata.src_id = silc_calloc(SILC_ID_CLIENT_LEN, sizeof(unsigned char));
     packetdata.src_id_len = SILC_ID_CLIENT_LEN;
+    src_id_allocated = TRUE;
   }
   packetdata.src_id_type = SILC_ID_CLIENT;
   if (dst_id) {
@@ -1486,7 +1488,7 @@ void silc_client_packet_send(SilcClient client,
   if (!silc_packet_assemble(&packetdata, client->rng, cipher, hmac, sock,
                             data, data_len, (const SilcBuffer)&packet)) {
     SILC_LOG_ERROR(("Error assembling packet"));
-    return;
+    goto out;
   }
 
   /* Encrypt the packet */
@@ -1499,6 +1501,12 @@ void silc_client_packet_send(SilcClient client,
 
   /* Now actually send the packet */
   silc_client_packet_send_real(client, sock, force_send);
+
+ out:
+  if (src_id_allocated && packetdata.src_id)
+    silc_free(packetdata.src_id);
+  if (packetdata.dst_id)
+    silc_free(packetdata.dst_id);
 }
 
 /* Packet sending routine for application.  This is the only routine that
@@ -1805,9 +1813,10 @@ void silc_client_receive_new_id(SilcClient client,
     silc_buffer_free(sidp);
 
     if (!conn->internal->params.detach_data) {
-      /* Send NICK command if the nickname was set by the application.
-        Send this with little timeout. */
-      if (client->nickname)
+      /* Send NICK command if the nickname was set by the application (and is
+        not same as the username). Send this with little timeout. */
+      if (client->nickname &&
+         !silc_utf8_strcasecmp(client->nickname, client->username))
        silc_schedule_task_add(client->schedule, 0,
                               silc_client_send_auto_nick, conn,
                               1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL);