comparison libpurple/protocols/myspace/message.c @ 24764:c044eb54b7ac

Fix a leak in myspace prpl. In myspace.c:msim_process_reply, the clone of 'msg' sent to the callbacks were never freed. Also, do not unnecessarily dup a static string (which needs to be marked for translation after the string freeze).
author Sadrul Habib Chowdhury <imadil@gmail.com>
date Wed, 17 Dec 2008 20:50:49 +0000
parents 6b7cd5769e98
children 22fd7467f0cc
comparison
equal deleted inserted replaced
24763:a8643ca8d2e0 24764:c044eb54b7ac
399 * For internal use - users probably want to use msim_msg_get() to 399 * For internal use - users probably want to use msim_msg_get() to
400 * access the MsimMessageElement *, instead of the GList * container. 400 * access the MsimMessageElement *, instead of the GList * container.
401 * 401 *
402 */ 402 */
403 static GList * 403 static GList *
404 msim_msg_get_node(MsimMessage *msg, const gchar *name) 404 msim_msg_get_node(const MsimMessage *msg, const gchar *name)
405 { 405 {
406 GList *node; 406 GList *node;
407 407
408 if (!name || !msg) { 408 if (!name || !msg) {
409 return NULL; 409 return NULL;
410 } 410 }
411 411
412 /* Linear search for the given name. O(n) but n is small. */ 412 /* Linear search for the given name. O(n) but n is small. */
413 for (node = msg; node != NULL; node = g_list_next(node)) { 413 for (node = (GList*)msg; node != NULL; node = g_list_next(node)) {
414 MsimMessageElement *elem; 414 MsimMessageElement *elem;
415 415
416 elem = (MsimMessageElement *)node->data; 416 elem = (MsimMessageElement *)node->data;
417 417
418 g_return_val_if_fail(elem != NULL, NULL); 418 g_return_val_if_fail(elem != NULL, NULL);
1064 * Note: useful fields of MsimMessageElement are 'data' and 'type', which 1064 * Note: useful fields of MsimMessageElement are 'data' and 'type', which
1065 * you can access directly. But it is often more convenient to use 1065 * you can access directly. But it is often more convenient to use
1066 * another msim_msg_get_* that converts the data to what type you want. 1066 * another msim_msg_get_* that converts the data to what type you want.
1067 */ 1067 */
1068 MsimMessageElement * 1068 MsimMessageElement *
1069 msim_msg_get(MsimMessage *msg, const gchar *name) 1069 msim_msg_get(const MsimMessage *msg, const gchar *name)
1070 { 1070 {
1071 GList *node; 1071 GList *node;
1072 1072
1073 node = msim_msg_get_node(msg, name); 1073 node = msim_msg_get_node(msg, name);
1074 if (node) { 1074 if (node) {
1113 * Note that msim_msg_pack_element_data() is similar, but returns a string 1113 * Note that msim_msg_pack_element_data() is similar, but returns a string
1114 * for inclusion into a raw protocol string (escaped and everything). 1114 * for inclusion into a raw protocol string (escaped and everything).
1115 * This function unescapes the string for you, if needed. 1115 * This function unescapes the string for you, if needed.
1116 */ 1116 */
1117 gchar * 1117 gchar *
1118 msim_msg_get_string(MsimMessage *msg, const gchar *name) 1118 msim_msg_get_string(const MsimMessage *msg, const gchar *name)
1119 { 1119 {
1120 MsimMessageElement *elem; 1120 MsimMessageElement *elem;
1121 1121
1122 elem = msim_msg_get(msg, name); 1122 elem = msim_msg_get(msg, name);
1123 if (!elem) { 1123 if (!elem) {
1183 1183
1184 /** 1184 /**
1185 * Return an element as a new list. Caller frees with msim_msg_list_free(). 1185 * Return an element as a new list. Caller frees with msim_msg_list_free().
1186 */ 1186 */
1187 GList * 1187 GList *
1188 msim_msg_get_list(MsimMessage *msg, const gchar *name) 1188 msim_msg_get_list(const MsimMessage *msg, const gchar *name)
1189 { 1189 {
1190 MsimMessageElement *elem; 1190 MsimMessageElement *elem;
1191 1191
1192 elem = msim_msg_get(msg, name); 1192 elem = msim_msg_get(msg, name);
1193 if (!elem) { 1193 if (!elem) {
1277 1277
1278 /** 1278 /**
1279 * Return an element as a new dictionary. Caller frees with msim_msg_free(). 1279 * Return an element as a new dictionary. Caller frees with msim_msg_free().
1280 */ 1280 */
1281 MsimMessage * 1281 MsimMessage *
1282 msim_msg_get_dictionary(MsimMessage *msg, const gchar *name) 1282 msim_msg_get_dictionary(const MsimMessage *msg, const gchar *name)
1283 { 1283 {
1284 MsimMessageElement *elem; 1284 MsimMessageElement *elem;
1285 1285
1286 elem = msim_msg_get(msg, name); 1286 elem = msim_msg_get(msg, name);
1287 if (!elem) { 1287 if (!elem) {
1319 * Useful to obtain an element's data if you know it should be an integer, 1319 * Useful to obtain an element's data if you know it should be an integer,
1320 * even if it is not stored as an MSIM_TYPE_INTEGER. MSIM_TYPE_STRING will 1320 * even if it is not stored as an MSIM_TYPE_INTEGER. MSIM_TYPE_STRING will
1321 * be converted handled correctly, for example. 1321 * be converted handled correctly, for example.
1322 */ 1322 */
1323 guint 1323 guint
1324 msim_msg_get_integer(MsimMessage *msg, const gchar *name) 1324 msim_msg_get_integer(const MsimMessage *msg, const gchar *name)
1325 { 1325 {
1326 MsimMessageElement *elem; 1326 MsimMessageElement *elem;
1327 1327
1328 elem = msim_msg_get(msg, name); 1328 elem = msim_msg_get(msg, name);
1329 1329
1396 * @param binary_length A pointer to an integer, which will be set to the binary data length. 1396 * @param binary_length A pointer to an integer, which will be set to the binary data length.
1397 * 1397 *
1398 * @return TRUE if successful, FALSE if not. 1398 * @return TRUE if successful, FALSE if not.
1399 */ 1399 */
1400 gboolean 1400 gboolean
1401 msim_msg_get_binary(MsimMessage *msg, const gchar *name, 1401 msim_msg_get_binary(const MsimMessage *msg, const gchar *name,
1402 gchar **binary_data, gsize *binary_length) 1402 gchar **binary_data, gsize *binary_length)
1403 { 1403 {
1404 MsimMessageElement *elem; 1404 MsimMessageElement *elem;
1405 1405
1406 elem = msim_msg_get(msg, name); 1406 elem = msim_msg_get(msg, name);