pidgin/pidgin

Fix SoupMessage leaks when using new libsoup3 API

19 months ago, Elliott Sales de Andrade
4371fa2ce648
Parents 6009bf441ef5
Children 7e1dd7e9efbb
Fix SoupMessage leaks when using new libsoup3 API

The new API takes a ref, not ownership, of the sent message, so we need to unref our copy.

The compatibility layer for libsoup2 similarly also takes a ref, so this is also leaking on libsoup2 now.

Also fix an incorrect data parameter in the gnttinyurl plugin (all the rest of the code was already changed expecting `msg` as the callback data.)

Testing Done:
Compile only.

Reviewed at https://reviews.imfreedom.org/r/2017/
--- a/finch/plugins/gnttinyurl/gnttinyurl.c Thu Nov 03 22:52:46 2022 -0500
+++ b/finch/plugins/gnttinyurl/gnttinyurl.c Thu Nov 03 22:53:41 2022 -0500
@@ -233,10 +233,12 @@
gnt_text_view_tag_change(tv, data->tag, str, FALSE);
g_free(str);
g_free(data->tag);
+ g_object_unref(data->msg);
g_free(data);
return;
}
g_free(data->tag);
+ g_object_unref(data->msg);
g_free(data);
purple_debug_info("TinyURL", "Conversation no longer exists... :(\n");
}
@@ -409,6 +411,7 @@
}
if (response_body == NULL) {
+ g_object_unref(msg);
return;
}
@@ -421,6 +424,7 @@
tinyurl_notify_tinyuri(win, url);
g_bytes_unref(response_body);
+ g_object_unref(msg);
}
static void *
@@ -473,7 +477,7 @@
g_free);
soup_session_send_and_read_async(session, msg, G_PRIORITY_DEFAULT,
- cancellable, tinyurl_notify_fetch_cb, win);
+ cancellable, tinyurl_notify_fetch_cb, msg);
g_signal_connect_object(win, "destroy", G_CALLBACK(g_cancellable_cancel),
cancellable, G_CONNECT_SWAPPED);
g_free(fullurl);
--- a/libpurple/protocols/facebook/api.c Thu Nov 03 22:52:46 2022 -0500
+++ b/libpurple/protocols/facebook/api.c Thu Nov 03 22:53:41 2022 -0500
@@ -798,6 +798,7 @@
JsonNode *root;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -807,6 +808,7 @@
}
json_node_free(root);
+ g_object_unref(soupmsg);
}
static void
@@ -989,6 +991,7 @@
JsonNode *root;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -1002,6 +1005,7 @@
FB_API_ERROR_EMIT(api, err,
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
return;
);
@@ -1018,6 +1022,7 @@
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
}
static void
@@ -2022,6 +2027,7 @@
static const gchar *imgexts[] = {".jpg", ".png", ".gif"};
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -2033,6 +2039,7 @@
FB_API_ERROR_EMIT(api, err,
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
return;
);
@@ -2055,7 +2062,7 @@
g_slist_free_full(msgs, (GDestroyNotify) fb_api_message_free);
g_object_unref(values);
json_node_free(root);
-
+ g_object_unref(soupmsg);
}
static void
@@ -2070,7 +2077,7 @@
http = fb_api_http_req(api, FB_API_URL_ATTACH, "getAttachment",
"messaging.getAttachment", prms,
- fb_api_cb_attach);
+ fb_api_cb_attach);
g_object_set_data_full(G_OBJECT(http), "fb-api-msg", msg,
(GDestroyNotify)fb_api_message_free);
}
@@ -2085,6 +2092,7 @@
JsonNode *root;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -2096,6 +2104,7 @@
FB_API_ERROR_EMIT(api, err,
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
return;
);
@@ -2106,6 +2115,7 @@
g_signal_emit_by_name(api, "auth");
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
}
void
@@ -2155,6 +2165,7 @@
JsonNode *root;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -2164,6 +2175,7 @@
fb_api_error_literal(api, FB_API_ERROR_GENERAL,
_("Failed to obtain contact information"));
json_node_free(root);
+ g_object_unref(soupmsg);
return;
}
@@ -2177,6 +2189,7 @@
FB_API_ERROR_EMIT(api, err,
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
return;
);
@@ -2192,6 +2205,7 @@
fb_api_user_reset(&user, TRUE);
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
}
void
@@ -2312,6 +2326,7 @@
JsonNode *node;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -2388,6 +2403,7 @@
json_node_free(croot);
json_node_free(root);
+ g_object_unref(soupmsg);
}
void
@@ -2626,6 +2642,7 @@
JsonNode *xode;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -2635,6 +2652,7 @@
fb_api_error_literal(api, FB_API_ERROR_GENERAL,
_("Failed to obtain unread messages"));
json_node_free(root);
+ g_object_unref(soupmsg);
return;
}
@@ -2645,6 +2663,7 @@
FB_API_ERROR_EMIT(api, err,
g_object_unref(values);
+ g_object_unref(soupmsg);
return;
);
@@ -2736,6 +2755,7 @@
g_slist_free_full(msgs, (GDestroyNotify) fb_api_message_free);
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
}
static void
@@ -2751,6 +2771,7 @@
JsonNode *root;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -2795,6 +2816,7 @@
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
}
void
@@ -2830,6 +2852,7 @@
JsonNode *root;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -2842,6 +2865,7 @@
FB_API_ERROR_EMIT(api, err,
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
return;
);
@@ -2854,6 +2878,7 @@
g_slist_free_full(msgs, (GDestroyNotify) fb_api_message_free);
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
}
static void
@@ -2957,6 +2982,7 @@
JsonNode *root;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -2966,6 +2992,7 @@
fb_api_error_literal(api, FB_API_ERROR_GENERAL,
_("Failed to obtain thread information"));
json_node_free(root);
+ g_object_unref(soupmsg);
return;
}
@@ -2988,6 +3015,7 @@
fb_api_thread_reset(&thrd, TRUE);
json_node_free(root);
+ g_object_unref(soupmsg);
}
void
@@ -3018,6 +3046,7 @@
JsonNode *root;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -3028,6 +3057,7 @@
FB_API_ERROR_EMIT(api, err,
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
return;
);
@@ -3037,6 +3067,7 @@
g_object_unref(values);
json_node_free(root);
+ g_object_unref(soupmsg);
}
void
@@ -3132,8 +3163,7 @@
fb_http_params_set_str(prms, "name", topic);
fb_http_params_set_int(prms, "tid", tid);
fb_api_http_req(api, FB_API_URL_TOPIC, "setThreadName",
- "messaging.setthreadname", prms,
- fb_api_cb_http_bool);
+ "messaging.setthreadname", prms, fb_api_cb_http_bool);
}
static void
@@ -3151,6 +3181,7 @@
JsonNode *root;
if (!fb_api_http_chk(api, session, result, soupmsg, &root)) {
+ g_object_unref(soupmsg);
return;
}
@@ -3158,6 +3189,7 @@
&err);
FB_API_ERROR_EMIT(api, err,
json_node_free(root);
+ g_object_unref(soupmsg);
return;
);
@@ -3189,6 +3221,7 @@
g_list_free(elms);
json_array_unref(arr);
json_node_free(root);
+ g_object_unref(soupmsg);
}
void
--- a/libpurple/protocols/facebook/data.c Thu Nov 03 22:52:46 2022 -0500
+++ b/libpurple/protocols/facebook/data.c Thu Nov 03 22:53:41 2022 -0500
@@ -511,6 +511,7 @@
}
g_object_unref(img);
+ g_object_unref(msg);
}
void
--- a/libpurple/protocols/jabber/bosh.c Thu Nov 03 22:52:46 2022 -0500
+++ b/libpurple/protocols/jabber/bosh.c Thu Nov 03 22:53:41 2022 -0500
@@ -252,6 +252,7 @@
node = jabber_bosh_connection_parse(bosh_conn, msg, response_body, error);
g_clear_pointer(&response_body, g_bytes_unref);
g_clear_error(&error);
+ g_clear_object(&msg);
if (node == NULL) {
return;
@@ -436,6 +437,7 @@
node = jabber_bosh_connection_parse(bosh_conn, msg, response_body, error);
g_clear_pointer(&response_body, g_bytes_unref);
g_clear_error(&error);
+ g_clear_object(&msg);
if (node == NULL) {
return;
--- a/libpurple/protocols/jabber/useravatar.c Thu Nov 03 22:52:46 2022 -0500
+++ b/libpurple/protocols/jabber/useravatar.c Thu Nov 03 22:53:41 2022 -0500
@@ -244,6 +244,7 @@
out:
g_free(info->from);
g_free(info->id);
+ g_object_unref(info->msg);
g_free(info);
g_clear_error(&error);
}