Fri, 05 Feb 2010 01:18:18 +0000
Check if memory has been freed by looking at its contents does not work
100% of the time. If any of these functions are called with an invalid
object, then the correct fix is to determine why the function was called
and prevent it from being called.
|
20153
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
1 | /* MySpaceIM Protocol Plugin, session |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
2 | * |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
3 | * Copyright (C) 2007, Jeff Connelly <jeff2@soc.pidgin.im> |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
4 | * |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
5 | * This program is free software; you can redistribute it and/or modify |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
6 | * it under the terms of the GNU General Public License as published by |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
7 | * the Free Software Foundation; either version 2 of the License, or |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
8 | * (at your option) any later version. |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
9 | * |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
10 | * This program is distributed in the hope that it will be useful, |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
13 | * GNU General Public License for more details. |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
14 | * |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
15 | * You should have received a copy of the GNU General Public License |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
16 | * along with this program; if not, write to the Free Software |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
18 | */ |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
19 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
20 | #include "myspace.h" |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
21 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
22 | /* Session methods */ |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
23 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
24 | /** |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
25 | * Create a new MSIM session. |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
26 | * |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
27 | * @param acct The account to create the session from. |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
28 | * |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
29 | * @return Pointer to a new session. Free with msim_session_destroy. |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
30 | */ |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
31 | MsimSession * |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
32 | msim_session_new(PurpleAccount *acct) |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
33 | { |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
34 | MsimSession *session; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
35 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
36 | g_return_val_if_fail(acct != NULL, NULL); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
37 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
38 | session = g_new0(MsimSession, 1); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
39 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
40 | session->magic = MSIM_SESSION_STRUCT_MAGIC; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
41 | session->account = acct; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
42 | session->gc = purple_account_get_connection(acct); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
43 | session->sesskey = 0; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
44 | session->userid = 0; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
45 | session->username = NULL; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
46 | session->fd = -1; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
47 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
48 | /* TODO: Remove. */ |
|
25197
077b4d6fc595
No functionality change--just cleanup.
Mark Doliner <markdoliner@pidgin.im>
parents:
24672
diff
changeset
|
49 | session->user_lookup_cb = g_hash_table_new_full(g_direct_hash, |
|
20153
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
50 | g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */ |
|
25197
077b4d6fc595
No functionality change--just cleanup.
Mark Doliner <markdoliner@pidgin.im>
parents:
24672
diff
changeset
|
51 | session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash, |
|
20153
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
52 | g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are, |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
53 | they could be integers inside gpointers |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
54 | or strings, so I don't freed them. |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
55 | Figure this out, once free cache. */ |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
56 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
57 | /* Created in msim_process_server_info() */ |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
58 | session->server_info = NULL; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
59 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
60 | session->rxoff = 0; |
|
22348
4b0b743ba8c5
In msimprpl, grow the read buffer if it gets full using g_realloc(), similar to
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
21730
diff
changeset
|
61 | session->rxsize = MSIM_READ_BUF_SIZE; |
|
4b0b743ba8c5
In msimprpl, grow the read buffer if it gets full using g_realloc(), similar to
Jeff Connelly <jeff2@soc.pidgin.im>
parents:
21730
diff
changeset
|
62 | session->rxbuf = g_new0(gchar, session->rxsize); |
|
20153
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
63 | session->next_rid = 1; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
64 | session->last_comm = time(NULL); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
65 | session->inbox_status = 0; |
|
21730
bc1897ec9281
applied changes from 6546cfd72ecd9aa76fc524aaf3ac48489aeb2a90
Kevin Stange <kstange@pidgin.im>
parents:
20376
diff
changeset
|
66 | session->inbox_handle = 0; |
|
25197
077b4d6fc595
No functionality change--just cleanup.
Mark Doliner <markdoliner@pidgin.im>
parents:
24672
diff
changeset
|
67 | |
|
20153
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
68 | return session; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
69 | } |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
70 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
71 | /** |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
72 | * Free a session. |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
73 | * |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
74 | * @param session The session to destroy. |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
75 | */ |
|
25197
077b4d6fc595
No functionality change--just cleanup.
Mark Doliner <markdoliner@pidgin.im>
parents:
24672
diff
changeset
|
76 | void |
|
20153
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
77 | msim_session_destroy(MsimSession *session) |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
78 | { |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
79 | session->magic = -1; |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
80 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
81 | g_free(session->rxbuf); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
82 | g_free(session->username); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
83 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
84 | /* TODO: Remove. */ |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
85 | g_hash_table_destroy(session->user_lookup_cb); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
86 | g_hash_table_destroy(session->user_lookup_cb_data); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
87 | |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
88 | if (session->server_info) { |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
89 | msim_msg_free(session->server_info); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
90 | } |
|
25197
077b4d6fc595
No functionality change--just cleanup.
Mark Doliner <markdoliner@pidgin.im>
parents:
24672
diff
changeset
|
91 | |
|
21730
bc1897ec9281
applied changes from 6546cfd72ecd9aa76fc524aaf3ac48489aeb2a90
Kevin Stange <kstange@pidgin.im>
parents:
20376
diff
changeset
|
92 | /* Stop checking the inbox at the end of the session. */ |
|
bc1897ec9281
applied changes from 6546cfd72ecd9aa76fc524aaf3ac48489aeb2a90
Kevin Stange <kstange@pidgin.im>
parents:
20376
diff
changeset
|
93 | if (session->inbox_handle) { |
|
bc1897ec9281
applied changes from 6546cfd72ecd9aa76fc524aaf3ac48489aeb2a90
Kevin Stange <kstange@pidgin.im>
parents:
20376
diff
changeset
|
94 | purple_timeout_remove(session->inbox_handle); |
|
bc1897ec9281
applied changes from 6546cfd72ecd9aa76fc524aaf3ac48489aeb2a90
Kevin Stange <kstange@pidgin.im>
parents:
20376
diff
changeset
|
95 | } |
|
bc1897ec9281
applied changes from 6546cfd72ecd9aa76fc524aaf3ac48489aeb2a90
Kevin Stange <kstange@pidgin.im>
parents:
20376
diff
changeset
|
96 | |
|
20153
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
97 | g_free(session); |
|
7cdc9e4882df
Kill CRLF line-endings to make sure this compiles on Solaris. This is a
Richard Laager <rlaager@pidgin.im>
parents:
19859
diff
changeset
|
98 | } |