Mercurial > pidgin
annotate libpurple/protocols/myspace/session.c @ 20658:7efdc052539d
Fix lots of little memory leaks in the MySpace protocol plugin.
GString's need to be free'd, and the string passed to g_string_new()
is duplicated when inserted into the GString, so it still needs
to be free'd.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 26 Sep 2007 07:25:22 +0000 |
parents | 51457cf3d27b |
children | 430827922828 |
rev | line source |
---|---|
19937
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
1 /* MySpaceIM Protocol Plugin, session |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
2 * |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
3 * Copyright (C) 2007, Jeff Connelly <jeff2@soc.pidgin.im> |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
4 * |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
5 * This program is free software; you can redistribute it and/or modify |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
6 * it under the terms of the GNU General Public License as published by |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
7 * the Free Software Foundation; either version 2 of the License, or |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
8 * (at your option) any later version. |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
9 * |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
10 * This program is distributed in the hope that it will be useful, |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
13 * GNU General Public License for more details. |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
14 * |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
15 * You should have received a copy of the GNU General Public License |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
16 * along with this program; if not, write to the Free Software |
20147
51457cf3d27b
merge of '0fb234fbd6f0cbba882df8df649a783fea7f312f'
Casey Harkins <charkins@pidgin.im>
diff
changeset
|
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
19937
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
18 */ |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
19 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
20 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
21 #include "myspace.h" |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
22 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
23 /* Session methods */ |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
24 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
25 /** |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
26 * Create a new MSIM session. |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
27 * |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
28 * @param acct The account to create the session from. |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
29 * |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
30 * @return Pointer to a new session. Free with msim_session_destroy. |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
31 */ |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
32 MsimSession * |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
33 msim_session_new(PurpleAccount *acct) |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
34 { |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
35 MsimSession *session; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
36 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
37 g_return_val_if_fail(acct != NULL, NULL); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
38 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
39 session = g_new0(MsimSession, 1); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
40 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
41 session->magic = MSIM_SESSION_STRUCT_MAGIC; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
42 session->account = acct; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
43 session->gc = purple_account_get_connection(acct); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
44 session->sesskey = 0; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
45 session->userid = 0; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
46 session->username = NULL; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
47 session->fd = -1; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
48 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
49 /* TODO: Remove. */ |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
50 session->user_lookup_cb = g_hash_table_new_full(g_direct_hash, |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
51 g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */ |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
52 session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash, |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
53 g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are, |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
54 they could be integers inside gpointers |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
55 or strings, so I don't freed them. |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
56 Figure this out, once free cache. */ |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
57 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
58 /* Created in msim_process_server_info() */ |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
59 session->server_info = NULL; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
60 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
61 session->rxoff = 0; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
62 session->rxbuf = g_new0(gchar, MSIM_READ_BUF_SIZE); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
63 session->next_rid = 1; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
64 session->last_comm = time(NULL); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
65 session->inbox_status = 0; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
66 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
67 return session; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
68 } |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
69 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
70 /** |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
71 * Free a session. |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
72 * |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
73 * @param session The session to destroy. |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
74 */ |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
75 void |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
76 msim_session_destroy(MsimSession *session) |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
77 { |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
78 g_return_if_fail(MSIM_SESSION_VALID(session)); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
79 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
80 session->magic = -1; |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
81 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
82 g_free(session->rxbuf); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
83 g_free(session->username); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
84 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
85 /* TODO: Remove. */ |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
86 g_hash_table_destroy(session->user_lookup_cb); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
87 g_hash_table_destroy(session->user_lookup_cb_data); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
88 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
89 if (session->server_info) { |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
90 msim_msg_free(session->server_info); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
91 } |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
92 |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
93 g_free(session); |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
94 } |
36ba89a2b7da
Replace all CRLF line-endings with LF line endings (Unix-style). This fixes
Jeffrey Connelly <jaconnel@calpoly.edu>
parents:
19433
diff
changeset
|
95 |