libpurple/protocols/jabber/message.h

Tue, 28 Feb 2023 03:23:06 -0600

author
Elliott Sales de Andrade <quantum.analyst@gmail.com>
date
Tue, 28 Feb 2023 03:23:06 -0600
changeset 42105
e431d160e3a1
parent 41239
735f7114318d
child 42305
a3895b6d3621
permissions
-rw-r--r--

Fix leaks in requests

Fixes a leak for images in requests:
```
3,627 bytes in 1 blocks are definitely lost in loss record 35,636 of 36,499
at 0x484386F: malloc (vg_replace_malloc.c:393)
by 0x4980168: g_malloc (gmem.c:130)
by 0x4995723: UnknownInlinedFun (gstrfuncs.c:426)
by 0x4995723: g_memdup2 (gstrfuncs.c:419)
by 0x4D3E534: purple_request_field_image_new (request.c:1677)
by 0x1CA970B1: purple_demo_protocol_request_fields_activate (purpledemoprotocolactions.c:553)
by 0x4DB5FBF: g_closure_invoke (gclosure.c:832)
by 0x4DE3D85: signal_emit_unlocked_R.isra.0 (gsignal.c:3796)
by 0x4DD3419: g_signal_emit_valist (gsignal.c:3549)
by 0x4DD3632: g_signal_emit (gsignal.c:3606)
by 0x581C784: g_simple_action_activate (gsimpleaction.c:227)
by 0x581B132: g_action_activate (gaction.c:399)
by 0x51221B6: UnknownInlinedFun (gtkmenutrackeritem.c:842)
by 0x51221B6: gtk_popover_item_activate.lto_priv.0 (gtkmenusectionbox.c:200)
```
and leak of the GObject wrapper for request fields:
```
4 bytes in 1 blocks are possibly lost in loss record 713 of 36,499
at 0x484386F: malloc (vg_replace_malloc.c:393)
by 0x4980168: g_malloc (gmem.c:130)
by 0x4995602: g_strdup (gstrfuncs.c:363)
by 0x488B324: create_list_field (gtkrequest.c:1504)
by 0x488D1D7: pidgin_request_fields (gtkrequest.c:2160)
by 0x4D3FFB8: purple_request_fields (request.c:2283)
by 0x1CA971D6: purple_demo_protocol_request_fields_activate (purpledemoprotocolactions.c:562)
by 0x4DB5FBF: g_closure_invoke (gclosure.c:832)
by 0x4DE3D85: signal_emit_unlocked_R.isra.0 (gsignal.c:3796)
by 0x4DD3419: g_signal_emit_valist (gsignal.c:3549)
by 0x4DD3632: g_signal_emit (gsignal.c:3606)
by 0x581C784: g_simple_action_activate (gsimpleaction.c:227)
56 bytes in 1 blocks are possibly lost in loss record 19,209 of 36,499
at 0x48486AF: realloc (vg_replace_malloc.c:1451)
by 0x498071F: g_realloc (gmem.c:201)
by 0x49592C4: g_data_set_internal (gdataset.c:474)
by 0x488B347: create_list_field (gtkrequest.c:1504)
by 0x488D1D7: pidgin_request_fields (gtkrequest.c:2160)
by 0x4D3FFB8: purple_request_fields (request.c:2283)
by 0x1CA971D6: purple_demo_protocol_request_fields_activate (purpledemoprotocolactions.c:562)
by 0x4DB5FBF: g_closure_invoke (gclosure.c:832)
by 0x4DE3D85: signal_emit_unlocked_R.isra.0 (gsignal.c:3796)
by 0x4DD3419: g_signal_emit_valist (gsignal.c:3549)
by 0x4DD3632: g_signal_emit (gsignal.c:3606)
by 0x581C784: g_simple_action_activate (gsimpleaction.c:227)
614 (192 direct, 422 indirect) bytes in 8 blocks are definitely lost in loss record 33,122 of 36,499
at 0x484386F: malloc (vg_replace_malloc.c:393)
by 0x4980168: g_malloc (gmem.c:130)
by 0x4997AB5: g_slice_alloc (gslice.c:1074)
by 0x49980EC: g_slice_alloc0 (gslice.c:1100)
by 0x4DDF04B: g_type_create_instance (gtype.c:1913)
by 0x4DC4C1F: g_object_new_internal (gobject.c:2228)
by 0x4DC6247: g_object_new_with_properties (gobject.c:2391)
by 0x4DC6FF0: g_object_new (gobject.c:2037)
by 0x488B2D5: create_list_field (gtkrequest.c:1499)
by 0x488D1D7: pidgin_request_fields (gtkrequest.c:2160)
by 0x4D3FFB8: purple_request_fields (request.c:2283)
by 0x1CA971D6: purple_demo_protocol_request_fields_activate (purpledemoprotocolactions.c:562)
```
and a request label:
```
128 bytes in 1 blocks are definitely lost in loss record 27,735 of 36,499
at 0x484378A: malloc (vg_replace_malloc.c:392)
by 0x484870B: realloc (vg_replace_malloc.c:1451)
by 0x498071F: g_realloc (gmem.c:201)
by 0x499A343: g_string_maybe_expand (gstring.c:92)
by 0x499A3BF: g_string_sized_new (gstring.c:116)
by 0x4981BCB: g_markup_escape_text (gmarkup.c:2323)
by 0x4887D8A: pidgin_request_escape (gtkrequest.c:360)
by 0x488CED9: pidgin_request_fields (gtkrequest.c:2105)
by 0x4D3FFB8: purple_request_fields (request.c:2283)
by 0x1CA971D6: purple_demo_protocol_request_fields_activate (purpledemoprotocolactions.c:562)
by 0x4DB5FBF: g_closure_invoke (gclosure.c:832)
by 0x4DE3D85: signal_emit_unlocked_R.isra.0 (gsignal.c:3796)
```
and one in the demo protocol:
```
40 bytes in 1 blocks are definitely lost in loss record 15,277 of 36,499
at 0x484386F: malloc (vg_replace_malloc.c:393)
by 0x4AE3017: __vasprintf_internal (vasprintf.c:71)
by 0x49C2E81: UnknownInlinedFun (stdio2.h:169)
by 0x49C2E81: g_vasprintf (gprintf.c:340)
by 0x4998EA0: g_strdup_vprintf (gstrfuncs.c:553)
by 0x4998F5C: g_strdup_printf (gstrfuncs.c:583)
by 0x1CA9584E: purple_demo_protocol_request_input_activate (purpledemoprotocolactions.c:203)
by 0x4DB5FBF: g_closure_invoke (gclosure.c:832)
by 0x4DE3D85: signal_emit_unlocked_R.isra.0 (gsignal.c:3796)
by 0x4DD3419: g_signal_emit_valist (gsignal.c:3549)
by 0x4DD3632: g_signal_emit (gsignal.c:3606)
by 0x581C784: g_simple_action_activate (gsimpleaction.c:227)
by 0x581B132: g_action_activate (gaction.c:399)
```

Testing Done:
Ran valgrind and confirmed above leaks were not there after opening Request Input and Request Fields.

Reviewed at https://reviews.imfreedom.org/r/2300/

7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
1 /**
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
2 * @file message.h Message handlers
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
3 *
15884
4de1981757fc sed -ie 's/gaim/purple/g'
Sean Egan <seanegan@pidgin.im>
parents: 15709
diff changeset
4 * purple
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
5 *
28322
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 27429
diff changeset
6 * Purple is the legal property of its developers, whose names are too numerous
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 27429
diff changeset
7 * to list here. Please refer to the COPYRIGHT file distributed with this
ac8fec1d2234 Remove specific copyright lines from the XMPP prpl.
Paul Aurich <darkrain42@pidgin.im>
parents: 27429
diff changeset
8 * source distribution.
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
9 *
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
10 * This program is free software; you can redistribute it and/or modify
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
11 * it under the terms of the GNU General Public License as published by
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
12 * the Free Software Foundation; either version 2 of the License, or
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
13 * (at your option) any later version.
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
14 *
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
15 * This program is distributed in the hope that it will be useful,
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
18 * GNU General Public License for more details.
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
19 *
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
20 * You should have received a copy of the GNU General Public License
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
21 * along with this program; if not, write to the Free Software
19859
71d37b57eff2 The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 15884
diff changeset
22 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
23 */
39819
3554dac2991b Standardize all protocol header guard macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39556
diff changeset
24
3554dac2991b Standardize all protocol header guard macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39556
diff changeset
25 #ifndef PURPLE_JABBER_MESSAGE_H
3554dac2991b Standardize all protocol header guard macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39556
diff changeset
26 #define PURPLE_JABBER_MESSAGE_H
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
27
40358
e6fe6fc1f516 move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually
Gary Kramlich <grim@reaperworld.com>
parents: 39819
diff changeset
28 #include <purple.h>
e6fe6fc1f516 move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually
Gary Kramlich <grim@reaperworld.com>
parents: 39819
diff changeset
29
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
30 #include "jabber.h"
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
31
39556
622bf98df0ac Remove unnecessary struct tags.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 36077
diff changeset
32 typedef struct {
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
33 JabberStream *js;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
34 enum {
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
35 JABBER_MESSAGE_NORMAL,
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
36 JABBER_MESSAGE_CHAT,
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
37 JABBER_MESSAGE_GROUPCHAT,
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
38 JABBER_MESSAGE_HEADLINE,
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
39 JABBER_MESSAGE_ERROR,
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
40 JABBER_MESSAGE_GROUPCHAT_INVITE,
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17768
diff changeset
41 JABBER_MESSAGE_EVENT,
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
42 JABBER_MESSAGE_OTHER
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
43 } type;
41239
735f7114318d Port JabberMessage->sent to GDateTime and use g_date_time_new_from_iso8601 instead of purple_str_to_time.
Gary Kramlich <grim@reaperworld.com>
parents: 41176
diff changeset
44 GDateTime *sent;
9584
1a6198375303 [gaim-migrate @ 10427]
Nathan Fredrickson <nathan@silverorange.com>
parents: 8400
diff changeset
45 gboolean delayed;
40742
2fc55152b79c Fix up the XEP-0280 carbons support.
Gary Kramlich <grim@reaperworld.com>
parents: 40697
diff changeset
46 gboolean forwarded;
2fc55152b79c Fix up the XEP-0280 carbons support.
Gary Kramlich <grim@reaperworld.com>
parents: 40697
diff changeset
47 gboolean outgoing;
13484
350fd422b021 [gaim-migrate @ 15859]
Sean Egan <seanegan@pidgin.im>
parents: 12216
diff changeset
48 char *id;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
49 char *from;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
50 char *to;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
51 char *subject;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
52 char *body;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
53 char *xhtml;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
54 char *password;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
55 char *error;
8400
09cd5dba5ca4 [gaim-migrate @ 9129]
Nathan Walp <nwalp@pidgin.im>
parents: 7971
diff changeset
56 char *thread_id;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
57 enum {
27429
3313d7d74962 Remove code for obsoleted XEP-0022 (Message Events)
Paul Aurich <darkrain42@pidgin.im>
parents: 26984
diff changeset
58 JM_STATE_NONE,
13708
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
59 JM_STATE_ACTIVE,
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
60 JM_STATE_COMPOSING,
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
61 JM_STATE_PAUSED,
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
62 JM_STATE_INACTIVE,
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
63 JM_STATE_GONE
37d5bc24e5bf [gaim-migrate @ 16110]
Nathan Walp <nwalp@pidgin.im>
parents: 13484
diff changeset
64 } chat_state;
7145
c77dd3b09666 [gaim-migrate @ 7712]
Nathan Walp <nwalp@pidgin.im>
parents: 7118
diff changeset
65 GList *etc;
17779
773326802e26 Fixed whitespace to match the coding convention used in libpurple
Andreas Monitzer <am@adiumx.com>
parents: 17768
diff changeset
66 GList *eventitems;
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
67 } JabberMessage;
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
68
7971
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7145
diff changeset
69 void jabber_message_free(JabberMessage *jm);
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7145
diff changeset
70
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7145
diff changeset
71 void jabber_message_send(JabberMessage *jm);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
72
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 34670
diff changeset
73 void jabber_message_parse(JabberStream *js, PurpleXmlNode *packet);
40507
77d7bc9e5151 Make PurpleProtocolIM a proper interface
Gary Kramlich <grim@reaperworld.com>
parents: 40358
diff changeset
74 int jabber_message_send_im(PurpleProtocolIM *pim, PurpleConnection *gc, PurpleMessage *msg);
40697
81f81f5d2f39 Split PurpleProtocolChat to its own file and clean up the API.
Gary Kramlich <grim@reaperworld.com>
parents: 40507
diff changeset
75 int jabber_message_send_chat(PurpleProtocolChat *protocol_chat, PurpleConnection *gc, int id, PurpleMessage *msg);
7014
11471fae7ba0 [gaim-migrate @ 7577]
Nathan Walp <nwalp@pidgin.im>
parents:
diff changeset
76
40507
77d7bc9e5151 Make PurpleProtocolIM a proper interface
Gary Kramlich <grim@reaperworld.com>
parents: 40358
diff changeset
77 unsigned int jabber_send_typing(PurpleProtocolIM *pim, PurpleConnection *gc, const char *who, PurpleIMTypingState state);
7971
a9309feca3c8 [gaim-migrate @ 8648]
Nathan Walp <nwalp@pidgin.im>
parents: 7145
diff changeset
78
39819
3554dac2991b Standardize all protocol header guard macros.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 39556
diff changeset
79 #endif /* PURPLE_JABBER_MESSAGE_H */

mercurial