From 6c6cc73da2e7c0655ae3718b6cb4f7625876f81c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Helleu?= Date: Sat, 13 Aug 2016 15:35:40 +0200 Subject: xfer: fix memory leak in case of memory error in xfer_chat_open_buffer() --- src/plugins/xfer/xfer-chat.c | 67 +++++++++++++++++++++++--------------------- 1 file changed, 35 insertions(+), 32 deletions(-) diff --git a/src/plugins/xfer/xfer-chat.c b/src/plugins/xfer/xfer-chat.c index f2325432f..33177c930 100644 --- a/src/plugins/xfer/xfer-chat.c +++ b/src/plugins/xfer/xfer-chat.c @@ -358,45 +358,48 @@ xfer_chat_open_buffer (struct t_xfer *xfer) length = strlen (xfer->plugin_name) + 8 + strlen (xfer->plugin_id) + 1 + strlen (xfer->remote_nick) + 1; name = malloc (length); - if (name) + if (!name) + return; + + snprintf (name, length, "%s_dcc.%s.%s", + xfer->plugin_name, xfer->plugin_id, xfer->remote_nick); + xfer->buffer = weechat_buffer_search (XFER_PLUGIN_NAME, name); + if (!xfer->buffer) { - snprintf (name, length, "%s_dcc.%s.%s", - xfer->plugin_name, xfer->plugin_id, xfer->remote_nick); - xfer->buffer = weechat_buffer_search (XFER_PLUGIN_NAME, name); + xfer->buffer = weechat_buffer_new ( + name, + &xfer_chat_buffer_input_cb, NULL, NULL, + &xfer_chat_buffer_close_cb, NULL, NULL); + buffer_created = 1; + + /* failed to create buffer ? then return */ if (!xfer->buffer) { - xfer->buffer = weechat_buffer_new ( - name, - &xfer_chat_buffer_input_cb, NULL, NULL, - &xfer_chat_buffer_close_cb, NULL, NULL); - buffer_created = 1; - - /* failed to create buffer ? then return */ - if (!xfer->buffer) - return; + free (name); + return; } + } - if (buffer_created) + if (buffer_created) + { + weechat_buffer_set (xfer->buffer, "title", _("xfer chat")); + if (!weechat_buffer_get_integer (xfer->buffer, "short_name_is_set")) { - weechat_buffer_set (xfer->buffer, "title", _("xfer chat")); - if (!weechat_buffer_get_integer (xfer->buffer, "short_name_is_set")) - { - weechat_buffer_set (xfer->buffer, "short_name", - xfer->remote_nick); - } - weechat_buffer_set (xfer->buffer, "localvar_set_type", "private"); - weechat_buffer_set (xfer->buffer, "localvar_set_nick", xfer->local_nick); - weechat_buffer_set (xfer->buffer, "localvar_set_channel", xfer->remote_nick); - weechat_buffer_set (xfer->buffer, "highlight_words_add", "$nick"); + weechat_buffer_set (xfer->buffer, "short_name", + xfer->remote_nick); } + weechat_buffer_set (xfer->buffer, "localvar_set_type", "private"); + weechat_buffer_set (xfer->buffer, "localvar_set_nick", xfer->local_nick); + weechat_buffer_set (xfer->buffer, "localvar_set_channel", xfer->remote_nick); + weechat_buffer_set (xfer->buffer, "highlight_words_add", "$nick"); + } - weechat_printf (xfer->buffer, - _("%s%s: connected to %s (%s) via xfer chat"), - weechat_prefix ("network"), - XFER_PLUGIN_NAME, - xfer->remote_nick, - xfer->remote_address_str); + weechat_printf (xfer->buffer, + _("%s%s: connected to %s (%s) via xfer chat"), + weechat_prefix ("network"), + XFER_PLUGIN_NAME, + xfer->remote_nick, + xfer->remote_address_str); - free (name); - } + free (name); } -- cgit v1.2.3