Mon Jun 18 22:21:37 CEST 2007 Jochen Eisinger <coffee@silcnet.org>
authorJochen Eisinger <coffee@silcnet.org>
Mon, 18 Jun 2007 20:23:22 +0000 (20:23 +0000)
committerJochen Eisinger <coffee@silcnet.org>
Mon, 18 Jun 2007 20:23:22 +0000 (20:23 +0000)
* Fix memory leaks reported by Matt Day.  Affected files are
  lib/silcclient/command_reply.c, lib/silcclient/client.c

* Rewrite signed public message handling, adopting the new
  hilight interface.  Affected file is
  apps/irssi/src/fe-common/silc/fe-silc-messages.c

CHANGES
apps/irssi/src/fe-common/silc/fe-silc-messages.c
lib/silcclient/client.c
lib/silcclient/command_reply.c

diff --git a/CHANGES b/CHANGES
index 4b5feddc52744007095c36bf414f2464f7f483e1..42731563e7c72584833b55fc078c2e613004e5f0 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,12 @@
+Mon Jun 18 22:21:37 CEST 2007  Jochen Eisinger <coffee@silcnet.org>
+
+       * Fix memory leaks reported by Matt Day.  Affected files are
+         lib/silcclient/command_reply.c, lib/silcclient/client.c
+
+       * Rewrite signed public message handling, adopting the new
+         hilight interface.  Affected file is
+         apps/irssi/src/fe-common/silc/fe-silc-messages.c
+
 Sat Apr 28 21:19:45 EEST 2007  Pekka Riikonen <priikone@silcnet.org>
 
        * Do not check for too new protocol version in during SKE,
index 475c9e9ef717e6c76d22897a73f1ed20afe65508..5d87ae25d372ed7cbf5b8c0befb26126352c575a 100644 (file)
@@ -10,7 +10,7 @@
   it under the terms of the GNU General Public License as published by
   the Free Software Foundation; either version 2 of the License, or
   (at your option) any later version.
-  
+
   This program is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
@@ -52,11 +52,12 @@ static void sig_signed_message_public(SERVER_REC * server, const char *msg,
                                      int verified)
 {
   CHANNEL_REC *chanrec;
-  NICK_REC *nickrec = NULL; /* we cheat here a little to keep the limit of 
+  NICK_REC *nickrec = NULL; /* we cheat here a little to keep the limit of
                               6 parameters to a signal handler ... */
   const char *nickmode, *printnick;
   int for_me, print_channel, level;
   char *color, *freemsg = NULL;
+  HILIGHT_REC *hilight;
 
   /* NOTE: this may return NULL if some channel is just closed with
      /WINDOW CLOSE and server still sends the few last messages */
@@ -66,9 +67,9 @@ static void sig_signed_message_public(SERVER_REC * server, const char *msg,
 
   for_me = !settings_get_bool("hilight_nick_matches") ? FALSE :
       nick_match_msg(chanrec, msg, server->nick);
-  color = for_me ? NULL :
-      hilight_match_nick(server, target, nick, address, MSGLEVEL_PUBLIC,
-                        msg);
+  hilight = for_me ? NULL :
+         hilight_match_nick(server, target, nick, address, MSGLEVEL_PUBLIC, msg);
+  color = (hilight == NULL) ? NULL : hilight_get_color(hilight);
 
   print_channel = chanrec == NULL ||
       !window_item_is_active((WI_ITEM_REC *) chanrec);
@@ -77,7 +78,7 @@ static void sig_signed_message_public(SERVER_REC * server, const char *msg,
     print_channel = TRUE;
 
   level = MSGLEVEL_PUBLIC;
-  if (for_me || color != NULL)
+  if (for_me)
     level |= MSGLEVEL_HILIGHT;
 
   if (settings_get_bool("emphasis"))
@@ -91,32 +92,31 @@ static void sig_signed_message_public(SERVER_REC * server, const char *msg,
   if (printnick == NULL)
     printnick = nick;
 
-  if (!print_channel) {
-    /* message to active channel in window */
-    if (color != NULL) {
-      /* highlighted nick */
-      printformat_module("fe-common/silc", server, target,
-                        level, VERIFIED_MSG(verified, SILCTXT_PUBMSG_HILIGHT),
-                        color, printnick, msg, nickmode);
-    } else {
-      printformat_module("fe-common/silc", server, target, level,
-                        for_me ? VERIFIED_MSG(verified, SILCTXT_PUBMSG_ME) :
-                                 VERIFIED_MSG(verified,SILCTXT_PUBMSG),
-                        printnick, msg, nickmode);
-    }
-  } else {
-    /* message to not existing/active channel */
-    if (color != NULL) {
-      /* highlighted nick */
-      printformat_module("fe-common/silc", server, target, level,
+  if (color != NULL) {
+    /* highlighted nick */
+    TEXT_DEST_REC dest;
+    format_create_dest(&dest, server, target, level, NULL);
+    hilight_update_text_dest(&dest,hilight);
+    if (!print_channel) /* message to active channel in windpw */
+      printformat_module_dest("fe-common/silc", &dest, 
+                VERIFIED_MSG(verified, SILCTXT_PUBMSG_HILIGHT),
+                color, printnick, msg, nickmode);
+    else /* message to not existing/active channel */
+      printformat_module_dest("fe-common/silc", &dest,
                         VERIFIED_MSG(verified, SILCTXT_PUBMSG_HILIGHT_CHANNEL),
                         color, printnick, target, msg, nickmode);
-    } else {
+
+  } else {
+    if (!print_channel)
+      printformat_module("fe-common/silc", server, target, level,
+                for_me ? VERIFIED_MSG(verified, SILCTXT_PUBMSG_ME) :
+                         VERIFIED_MSG(verified,SILCTXT_PUBMSG),
+                printnick, msg, nickmode);
+    else
       printformat_module("fe-common/silc", server, target, level,
                         for_me ? VERIFIED_MSG(verified, SILCTXT_PUBMSG_ME_CHANNEL) :
                         VERIFIED_MSG(verified, SILCTXT_PUBMSG_CHANNEL),
                         printnick, target, msg, nickmode);
-    }
   }
 
   g_free_not_null(freemsg);
@@ -225,7 +225,7 @@ static void sig_signed_message_own_private(SERVER_REC * server,
   g_free_not_null(freemsg);
 }
 
-static void sig_message_own_action_all(SERVER_REC *server, 
+static void sig_message_own_action_all(SERVER_REC *server,
                                        const char *msg, const char *target,
                                        bool is_channel, bool is_signed)
 {
@@ -243,7 +243,7 @@ static void sig_message_own_action_all(SERVER_REC *server,
   printformat(server, target,
              MSGLEVEL_ACTIONS | MSGLEVEL_NOHILIGHT | MSGLEVEL_NO_ACT |
              (is_channel ? MSGLEVEL_PUBLIC : MSGLEVEL_MSGS),
-             item != NULL ? 
+             item != NULL ?
              (is_signed ? SILCTXT_OWN_ACTION_SIGNED : SILCTXT_OWN_ACTION) :
              (is_signed ? SILCTXT_OWN_ACTION_TARGET_SIGNED :
                           SILCTXT_OWN_ACTION_TARGET),
@@ -300,11 +300,11 @@ static void sig_message_action_all(SERVER_REC *server, const char *msg,
     msg = freemsg = expand_emphasis(item, msg);
 
   if (is_channel) {
-    /* channel action */ 
+    /* channel action */
     if (window_item_is_active(item)) {
       /* message to active channel in window */
       printformat(server, target, level,
-                 VERIFIED_MSG2(verified, SILCTXT_ACTION_PUBLIC), 
+                 VERIFIED_MSG2(verified, SILCTXT_ACTION_PUBLIC),
                  nick, target, msg);
     } else {
       /* message to not existing/active channel */
@@ -352,7 +352,7 @@ static void sig_message_private_action_signed(SERVER_REC *server,
   sig_message_action_all(server, msg, nick, address, target, FALSE, verified);
 }
 
-static void sig_message_own_notice_all(SERVER_REC *server, 
+static void sig_message_own_notice_all(SERVER_REC *server,
                                        const char *msg, const char *target,
                                        bool is_signed)
 {
@@ -383,9 +383,9 @@ static void sig_message_notice_all(SERVER_REC *server, const char *msg,
     return;
 
   if (is_channel) {
-    /* channel notice */ 
+    /* channel notice */
       printformat(server, target, MSGLEVEL_NOTICES,
-                 VERIFIED_MSG2(verified, SILCTXT_NOTICE_PUBLIC), 
+                 VERIFIED_MSG2(verified, SILCTXT_NOTICE_PUBLIC),
                  nick, target, msg);
   } else {
     /* private notice */
index 6119198166981a6afcf073c910356326384c4bcd..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
index 5c64922e3992af206be3aded6576c9f6a421f96c..13fab10a168ad506500ec3996b8be031ef4c3ccd 100644 (file)
@@ -131,7 +131,7 @@ void silc_client_command_reply_process(SilcClient client,
       /* No specific identifier for command reply, call first one found */
       (*reply)(ctx, NULL);
     else
-      silc_free(ctx);
+      silc_client_command_reply_free(ctx);
   }
 }
 
@@ -155,6 +155,8 @@ void silc_client_command_reply_free(SilcClientCommandReplyContext cmd)
   SILC_LOG_DEBUG(("Command reply context %p refcnt %d->%d", cmd,
                  cmd->users + 1, cmd->users));
   if (cmd->users < 1) {
+    if (cmd->callbacks)
+      silc_free(cmd->callbacks);
     silc_command_payload_free(cmd->payload);
     silc_free(cmd);
   }
@@ -934,7 +936,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping)
 {
   SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context;
   SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data;
-  void *id;
+  void *id = NULL;
   int i;
   time_t diff, curtime;
 
@@ -972,12 +974,12 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping)
     }
   }
 
-  silc_free(id);
-
   /* Notify application */
   COMMAND_REPLY((SILC_ARGS));
 
  out:
+  if (id)
+    silc_free(id);
   SILC_CLIENT_PENDING_EXEC(cmd, SILC_COMMAND_PING);
   silc_client_command_reply_free(cmd);
 }