1
0
mirror of https://github.com/weechat/weechat.git synced 2026-06-12 14:14:48 +02:00

relay/api: fix memory leak in receive of message from remote WeeChat

This commit is contained in:
Sébastien Helleu
2026-02-16 18:57:14 +01:00
parent 113f72f70e
commit 05f9129e65
3 changed files with 41 additions and 30 deletions
+1
View File
@@ -12,6 +12,7 @@ SPDX-License-Identifier: GPL-3.0-or-later
- irc: ignore self join if the channel is already joined ([#2291](https://github.com/weechat/weechat/issues/2291))
- relay/api: fix memory leaks in resources "ping" and "sync"
- relay/api: fix memory leak in receive of message from remote WeeChat
## Version 4.8.1 (2025-12-01)
@@ -1283,7 +1283,15 @@ relay_remote_event_recv (struct t_relay_remote *remote, const char *data)
json = cJSON_Parse (data);
if (!json)
goto error_data;
{
weechat_printf (
NULL,
_("%sremote[%s]: invalid data received from remote relay: \"%s\""),
weechat_prefix ("error"),
remote->name,
data);
return;
}
event.remote = remote;
event.name = NULL;
@@ -1296,7 +1304,7 @@ relay_remote_event_recv (struct t_relay_remote *remote, const char *data)
json_body = cJSON_GetObjectItem (json, "body");
if (!body_type && ((code == 200) || (code == 204)))
return;
goto end;
JSON_GET_STR(json, event_name);
event.name = event_name;
@@ -1352,7 +1360,15 @@ relay_remote_event_recv (struct t_relay_remote *remote, const char *data)
rc = (callback) (&event);
}
if (rc == WEECHAT_RC_ERROR)
goto error_cb;
{
weechat_printf (
NULL,
_("%sremote[%s]: callback failed for body type \"%s\""),
weechat_prefix ("error"),
remote->name,
body_type);
goto end;
}
}
if (!remote->synced && initial_sync)
@@ -1361,23 +1377,6 @@ relay_remote_event_recv (struct t_relay_remote *remote, const char *data)
weechat_bar_item_update ("input_prompt");
}
return;
error_data:
weechat_printf (
NULL,
_("%sremote[%s]: invalid data received from remote relay: \"%s\""),
weechat_prefix ("error"),
remote->name,
data);
return;
error_cb:
weechat_printf (
NULL,
_("%sremote[%s]: callback failed for body type \"%s\""),
weechat_prefix ("error"),
remote->name,
body_type);
return;
end:
cJSON_Delete (json);
}
@@ -156,6 +156,7 @@ relay_remote_network_check_auth (struct t_relay_remote *remote,
int accept_ok, hash_size;
http_resp = NULL;
json_body = NULL;
msg_error = NULL;
msg_resp_error = NULL;
accept_ok = 0;
@@ -225,6 +226,9 @@ relay_remote_network_check_auth (struct t_relay_remote *remote,
relay_http_response_free (http_resp);
if (json_body)
cJSON_Delete (json_body);
return 1;
error:
@@ -238,6 +242,8 @@ error:
(msg_resp_error) ? msg_resp_error : "",
(msg_resp_error) ? ")" : "");
relay_http_response_free (http_resp);
if (json_body)
cJSON_Delete (json_body);
return 0;
}
@@ -1200,6 +1206,8 @@ relay_remote_network_url_handshake_cb (const void *pointer,
remote->hook_url_handshake = NULL;
json_body = NULL;
ptr_resp_code = weechat_hashtable_get (output, "response_code");
if (ptr_resp_code && ptr_resp_code[0] && (strcmp (ptr_resp_code, "200") != 0))
{
@@ -1211,7 +1219,7 @@ relay_remote_network_url_handshake_cb (const void *pointer,
weechat_config_string (remote->options[RELAY_REMOTE_OPTION_URL]),
ptr_resp_code);
relay_remote_network_disconnect (remote);
return WEECHAT_RC_OK;
goto end;
}
ptr_error = weechat_hashtable_get (output, "error");
@@ -1225,7 +1233,7 @@ relay_remote_network_url_handshake_cb (const void *pointer,
weechat_config_string (remote->options[RELAY_REMOTE_OPTION_URL]),
ptr_error);
relay_remote_network_disconnect (remote);
return WEECHAT_RC_OK;
goto end;
}
ptr_output = weechat_hashtable_get (output, "output");
@@ -1262,7 +1270,7 @@ relay_remote_network_url_handshake_cb (const void *pointer,
weechat_config_string (remote->options[RELAY_REMOTE_OPTION_URL]),
_("hash algorithm not found"));
relay_remote_network_disconnect (remote);
return WEECHAT_RC_OK;
goto end;
}
if (remote->password_hash_iterations < 0)
@@ -1275,7 +1283,7 @@ relay_remote_network_url_handshake_cb (const void *pointer,
weechat_config_string (remote->options[RELAY_REMOTE_OPTION_URL]),
_("unknown number of hash iterations"));
relay_remote_network_disconnect (remote);
return WEECHAT_RC_OK;
goto end;
}
if (remote->totp < 0)
@@ -1288,7 +1296,7 @@ relay_remote_network_url_handshake_cb (const void *pointer,
weechat_config_string (remote->options[RELAY_REMOTE_OPTION_URL]),
_("unknown TOTP status"));
relay_remote_network_disconnect (remote);
return WEECHAT_RC_OK;
goto end;
}
if (weechat_relay_plugin->debug >= 1)
@@ -1325,7 +1333,7 @@ relay_remote_network_url_handshake_cb (const void *pointer,
weechat_prefix ("error"),
remote->name);
relay_remote_network_disconnect (remote);
return WEECHAT_RC_OK;
goto end;
}
snprintf (option_name, length, "weechat.proxy.%s.type", proxy);
proxy_type = weechat_config_get (option_name);
@@ -1343,7 +1351,7 @@ relay_remote_network_url_handshake_cb (const void *pointer,
_("%sremote[%s]: proxy \"%s\" not found, cannot connect"),
weechat_prefix ("error"), remote->name, proxy);
relay_remote_network_disconnect (remote);
return WEECHAT_RC_OK;
goto end;
}
str_proxy_type = weechat_config_string (proxy_type);
str_proxy_address = weechat_config_string (proxy_address);
@@ -1356,7 +1364,7 @@ relay_remote_network_url_handshake_cb (const void *pointer,
"proxy \"%s\""),
weechat_prefix ("error"), remote->name, proxy);
relay_remote_network_disconnect (remote);
return WEECHAT_RC_OK;
goto end;
}
}
@@ -1375,6 +1383,9 @@ relay_remote_network_url_handshake_cb (const void *pointer,
remote,
NULL);
end:
if (json_body)
cJSON_Delete (json_body);
return WEECHAT_RC_OK;
}