fixes for silc client memory leaks
Matt Day <silcdevel-fQsKmw+gZb/[email protected]>
| Newsgroups | gmane.network.silc.devel |
|---|---|
| Message-ID | <[email protected]> |
Dear silc client developers, Below are patches for memory leaks that I have found in silc client version 1.0.3; I have confirmed that the bugs still remain in version 1.0.4.1. Haven't looked at 1.1.x yet. Without these fixes, long-running silc clients leak memory pretty rapidly, on the order of 100 KB/day. With these fixes, the client still seems to leak, but much more slowly, perhaps on the order of 4K per day. I haven't tracked down the remaining leaks yet. ccmalloc was very useful in tracking down these leaks, by the way: http://www.inf.ethz.ch/personal/biere/projects/ccmalloc/ If you have any questions about these fixes, please let me know! I think they're fairly self-explanatory. Thanks, Matt Day <silcdevel-fQsKmw+gZb/[email protected]> --- lib/silcclient/client.c.orig Wed Mar 30 22:07:10 2005 +++ lib/silcclient/client.c Sun Jun 5 13:30:30 2005 @@ -1418,6 +1418,7 @@ const SilcBufferStruct packet; int block_len; SilcUInt32 sequence = 0; + int src_id_allocated = FALSE; if (!sock) return; @@ -1461,6 +1462,7 @@ } 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 @@ 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 @@ /* 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 --- lib/silcclient/command_reply.c.orig Wed Mar 30 22:07:10 2005 +++ lib/silcclient/command_reply.c Sun Jun 5 13:40:50 2005 @@ -131,7 +131,7 @@ /* 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 @@ 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); } @@ -918,7 +920,7 @@ { SilcClientCommandReplyContext cmd = (SilcClientCommandReplyContext)context; SilcClientConnection conn = (SilcClientConnection)cmd->sock->user_data; - void *id; + void *id = NULL; int i; time_t diff, curtime; @@ -956,12 +958,12 @@ } } - 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); } _______________________________________________________________________ Info: https://lists.silcnet.org/mailman/listinfo/silc-announce Archive: https://lists.silcnet.org/pipermail/silc-announce FAQ: http://silcnet.org/support/faq/