summaryrefslogtreecommitdiff
path: root/src/plugins/xfer/xfer.c
diff options
context:
space:
mode:
authorSébastien Helleu <flashcode@flashtux.org>2019-10-05 17:49:07 +0200
committerSébastien Helleu <flashcode@flashtux.org>2019-10-05 17:49:07 +0200
commit6c23f632b12de9f43026b72626ccbc57cbbd9aa5 (patch)
treea82f2f29f1b0acc708ba0eabe6874af4144d9332 /src/plugins/xfer/xfer.c
parent3e189fa60d60ed24b7eceb14d1c475348cf392d3 (diff)
downloadweechat-6c23f632b12de9f43026b72626ccbc57cbbd9aa5.zip
xfer: fix memory leak when a xfer is freed and when the plugin is unloaded
Diffstat (limited to 'src/plugins/xfer/xfer.c')
-rw-r--r--src/plugins/xfer/xfer.c46
1 files changed, 38 insertions, 8 deletions
diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c
index 4936a6d36..680806318 100644
--- a/src/plugins/xfer/xfer.c
+++ b/src/plugins/xfer/xfer.c
@@ -465,9 +465,16 @@ xfer_alloc ()
time_now = time (NULL);
- /* default values */
+ new_xfer->plugin_id = NULL;
+ new_xfer->plugin_name = NULL;
+ new_xfer->type = 0;
+ new_xfer->protocol = 0;
+ new_xfer->remote_nick = NULL;
+ new_xfer->local_nick = NULL;
+ new_xfer->charset_modifier = NULL;
new_xfer->filename = NULL;
new_xfer->size = 0;
+ new_xfer->proxy = NULL;
new_xfer->local_address = NULL;
new_xfer->local_address_length = 0;
new_xfer->local_address_str = NULL;
@@ -475,16 +482,11 @@ xfer_alloc ()
new_xfer->remote_address_length = 0;
new_xfer->remote_address_str = NULL;
new_xfer->port = 0;
- new_xfer->remote_nick = NULL;
- new_xfer->local_nick = NULL;
- new_xfer->charset_modifier = NULL;
-
- new_xfer->type = 0;
- new_xfer->protocol = 0;
new_xfer->status = 0;
new_xfer->buffer = NULL;
new_xfer->remote_nick_color = NULL;
new_xfer->fast_send = weechat_config_boolean (xfer_config_network_fast_send);
+ new_xfer->send_ack = weechat_config_boolean (xfer_config_network_send_ack);
new_xfer->blocksize = weechat_config_integer (xfer_config_network_blocksize);
new_xfer->start_time = time_now;
new_xfer->start_transfer = time_now;
@@ -501,13 +503,15 @@ xfer_alloc ()
new_xfer->filename_suffix = -1;
new_xfer->pos = 0;
new_xfer->ack = 0;
- new_xfer->send_ack = weechat_config_boolean (xfer_config_network_send_ack);
new_xfer->start_resume = 0;
new_xfer->last_check_time = time_now;
new_xfer->last_check_pos = time_now;
new_xfer->last_activity = 0;
new_xfer->bytes_per_sec = 0;
new_xfer->eta = 0;
+ new_xfer->hash_handle = NULL;
+ new_xfer->hash_target = NULL;
+ new_xfer->hash_status = XFER_HASH_STATUS_UNKNOWN;
new_xfer->prev_xfer = NULL;
new_xfer->next_xfer = xfer_list;
@@ -917,6 +921,8 @@ xfer_free (struct t_xfer *xfer)
/* free data */
if (xfer->plugin_id)
free (xfer->plugin_id);
+ if (xfer->plugin_name)
+ free (xfer->plugin_name);
if (xfer->remote_nick)
free (xfer->remote_nick);
if (xfer->local_nick)
@@ -925,6 +931,8 @@ xfer_free (struct t_xfer *xfer)
free (xfer->charset_modifier);
if (xfer->filename)
free (xfer->filename);
+ if (xfer->proxy)
+ free (xfer->proxy);
if (xfer->local_address)
free (xfer->local_address);
if (xfer->local_address_str)
@@ -933,8 +941,16 @@ xfer_free (struct t_xfer *xfer)
free (xfer->remote_address);
if (xfer->remote_address_str)
free (xfer->remote_address_str);
+ if (xfer->buffer)
+ free (xfer->buffer);
if (xfer->remote_nick_color)
free (xfer->remote_nick_color);
+ if (xfer->hook_fd)
+ weechat_unhook (xfer->hook_fd);
+ if (xfer->hook_timer)
+ weechat_unhook (xfer->hook_timer);
+ if (xfer->hook_connect)
+ weechat_unhook (xfer->hook_connect);
if (xfer->unterminated_message)
free (xfer->unterminated_message);
if (xfer->local_filename)
@@ -956,6 +972,18 @@ xfer_free (struct t_xfer *xfer)
xfer_buffer_selected_line = (xfer_count == 0) ? 0 : xfer_count - 1;
}
+/*
+ * Frees all xfers.
+ */
+
+void
+xfer_free_all ()
+{
+ while (xfer_list)
+ {
+ xfer_free (xfer_list);
+ }
+}
/*
* Resolves address.
@@ -1860,5 +1888,7 @@ weechat_plugin_end (struct t_weechat_plugin *plugin)
else
xfer_disconnect_all ();
+ xfer_free_all ();
+
return WEECHAT_RC_OK;
}