diff options
author | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-25 00:02:13 +0200 |
---|---|---|
committer | Sébastien Helleu <flashcode@flashtux.org> | 2024-04-25 20:59:25 +0200 |
commit | 590d9453a0a4f7b9ad28ba829c48ee20695b2c80 (patch) | |
tree | 6a53d5099f4398f7de94bd05dcd1c019a214bcb0 /src/plugins | |
parent | ea85d180e5fc4a23bd7beef64f21f5b376fbce32 (diff) | |
download | weechat-590d9453a0a4f7b9ad28ba829c48ee20695b2c80.zip |
xfer: remove check of NULL pointers before calling free() (issue #865)
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/xfer/xfer-buffer.c | 12 | ||||
-rw-r--r-- | src/plugins/xfer/xfer-chat.c | 24 | ||||
-rw-r--r-- | src/plugins/xfer/xfer-file.c | 9 | ||||
-rw-r--r-- | src/plugins/xfer/xfer.c | 75 |
4 files changed, 40 insertions, 80 deletions
diff --git a/src/plugins/xfer/xfer-buffer.c b/src/plugins/xfer/xfer-buffer.c index 271220cac..d01199486 100644 --- a/src/plugins/xfer/xfer-buffer.c +++ b/src/plugins/xfer/xfer-buffer.c @@ -240,14 +240,10 @@ xfer_buffer_refresh (const char *hotlist) (str_total) ? str_total : "?", eta, str_bytes_per_sec); - if (progress_bar) - free (progress_bar); - if (str_pos) - free (str_pos); - if (str_total) - free (str_total); - if (str_bytes_per_sec) - free (str_bytes_per_sec); + free (progress_bar); + free (str_pos); + free (str_total); + free (str_bytes_per_sec); } line++; } diff --git a/src/plugins/xfer/xfer-chat.c b/src/plugins/xfer/xfer-chat.c index dde64e20f..80506a95a 100644 --- a/src/plugins/xfer/xfer-chat.c +++ b/src/plugins/xfer/xfer-chat.c @@ -93,8 +93,7 @@ xfer_chat_sendf (struct t_xfer *xfer, const char *format, ...) xfer_close (xfer, XFER_STATUS_FAILED); } - if (msg_encoded) - free (msg_encoded); + free (msg_encoded); free (vbuffer); } @@ -224,8 +223,7 @@ xfer_chat_recv_cb (const void *pointer, void *data, int fd) (pv_tags && pv_tags[0]) ? "," : "", (str_color) ? str_color : "default", xfer->remote_nick); - if (str_color) - free (str_color); + free (str_color); weechat_printf_date_tags ( xfer->buffer, 0, @@ -237,19 +235,15 @@ xfer_chat_recv_cb (const void *pointer, void *data, int fd) xfer->remote_nick, ptr_buf2); } - if (ptr_buf_decoded) - free (ptr_buf_decoded); - if (ptr_buf_without_weechat_colors) - free (ptr_buf_without_weechat_colors); - if (ptr_buf_color) - free (ptr_buf_color); + free (ptr_buf_decoded); + free (ptr_buf_without_weechat_colors); + free (ptr_buf_color); } ptr_buf = next_ptr_buf; } - if (buf2) - free (buf2); + free (buf2); } else { @@ -290,8 +284,7 @@ xfer_chat_buffer_input_cb (const void *pointer, void *data, "irc_privmsg,no_highlight,prefix_nick_%s,nick_%s,log1", (str_color) ? str_color : "default", ptr_xfer->local_nick); - if (str_color) - free (str_color); + free (str_color); input_data_color = weechat_hook_modifier_exec ("irc_color_decode", "1", input_data); @@ -303,8 +296,7 @@ xfer_chat_buffer_input_cb (const void *pointer, void *data, weechat_color ("chat_nick_self"), ptr_xfer->local_nick, (input_data_color) ? input_data_color : input_data); - if (input_data_color) - free (input_data_color); + free (input_data_color); } } } diff --git a/src/plugins/xfer/xfer-file.c b/src/plugins/xfer/xfer-file.c index 0ae4a29d0..6c39c69ae 100644 --- a/src/plugins/xfer/xfer-file.c +++ b/src/plugins/xfer/xfer-file.c @@ -216,10 +216,8 @@ error: rc = 1; end: - if (new_filename) - free (new_filename); - if (new_temp_filename) - free (new_temp_filename); + free (new_filename); + free (new_temp_filename); return rc; } @@ -299,8 +297,7 @@ xfer_file_find_filename (struct t_xfer *xfer) { strcat (xfer->local_filename, dir_separator); } - if (dir_separator) - free (dir_separator); + free (dir_separator); if (weechat_config_boolean (xfer_config_file_use_nick_in_filename)) { strcat (xfer->local_filename, xfer->remote_nick); diff --git a/src/plugins/xfer/xfer.c b/src/plugins/xfer/xfer.c index 7096edb55..7f64a4e43 100644 --- a/src/plugins/xfer/xfer.c +++ b/src/plugins/xfer/xfer.c @@ -670,8 +670,7 @@ xfer_new (const char *plugin_name, const char *plugin_id, new_xfer->remote_nick = strdup (remote_nick); color = weechat_info_get ("irc_nick_color_name", remote_nick); new_xfer->remote_nick_color = (color) ? strdup (color) : NULL; - if (color) - free (color); + free (color); new_xfer->local_nick = (local_nick) ? strdup (local_nick) : NULL; new_xfer->charset_modifier = (charset_modifier) ? strdup (charset_modifier) : NULL; if (XFER_IS_FILE(type)) @@ -875,15 +874,13 @@ void xfer_set_remote_address (struct t_xfer *xfer, const struct sockaddr *address, socklen_t length, const char *address_str) { - if (xfer->remote_address) - free (xfer->remote_address); + free (xfer->remote_address); xfer->remote_address = malloc (length); xfer->remote_address_length = length; if (xfer->remote_address) memcpy (xfer->remote_address, address, length); - if (xfer->remote_address_str) - free (xfer->remote_address_str); + free (xfer->remote_address_str); xfer->remote_address_str = strdup ((address_str) ? address_str : ""); } @@ -894,15 +891,13 @@ void xfer_set_local_address (struct t_xfer *xfer, const struct sockaddr *address, socklen_t length, const char *address_str) { - if (xfer->local_address) - free (xfer->local_address); + free (xfer->local_address); xfer->local_address = malloc (length); xfer->local_address_length = length; if (xfer->local_address) memcpy (xfer->local_address, address, length); - if (xfer->local_address_str) - free (xfer->local_address_str); + free (xfer->local_address_str); xfer->local_address_str = strdup ((address_str) ? address_str : ""); } @@ -932,49 +927,33 @@ xfer_free (struct t_xfer *xfer) (xfer->next_xfer)->prev_xfer = xfer->prev_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) - free (xfer->local_nick); - if (xfer->charset_modifier) - 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) - free (xfer->local_address_str); - if (xfer->remote_address) - free (xfer->remote_address); - if (xfer->remote_address_str) - free (xfer->remote_address_str); - if (xfer->remote_nick_color) - free (xfer->remote_nick_color); + free (xfer->plugin_id); + free (xfer->plugin_name); + free (xfer->remote_nick); + free (xfer->local_nick); + free (xfer->charset_modifier); + free (xfer->filename); + free (xfer->proxy); + free (xfer->local_address); + free (xfer->local_address_str); + free (xfer->remote_address); + free (xfer->remote_address_str); + 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) - free (xfer->local_filename); - if (xfer->temp_local_filename) - free (xfer->temp_local_filename); + free (xfer->unterminated_message); + free (xfer->local_filename); + free (xfer->temp_local_filename); if (xfer->hash_handle) { gcry_md_close (*xfer->hash_handle); free (xfer->hash_handle); } - if (xfer->hash_target) - free (xfer->hash_target); + free (xfer->hash_target); free (xfer); @@ -1396,18 +1375,14 @@ xfer_add_cb (const void *pointer, void *data, if (XFER_IS_SEND(ptr_xfer->type) && !XFER_HAS_ENDED(ptr_xfer->status)) xfer_send_signal (ptr_xfer, "xfer_send_ready"); - if (filename2) - free (filename2); - if (short_filename) - free (short_filename); + free (filename2); + free (short_filename); weechat_infolist_reset_item_cursor (infolist); return WEECHAT_RC_OK_EAT; error: - if (filename2) - free (filename2); - if (short_filename) - free (short_filename); + free (filename2); + free (short_filename); weechat_infolist_reset_item_cursor (infolist); return WEECHAT_RC_ERROR; } |