Mercurial > pidgin
comparison libpurple/protocols/myspace/myspace.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 | b8962a8c5daa |
children | 324c25c2daad |
comparison
equal
deleted
inserted
replaced
20657:c2c263d47534 | 20658:7efdc052539d |
---|---|
41 static void print_hash_item(gpointer key, gpointer value, gpointer user_data); | 41 static void print_hash_item(gpointer key, gpointer value, gpointer user_data); |
42 #endif | 42 #endif |
43 | 43 |
44 static int msim_send_really_raw(PurpleConnection *gc, const char *buf, int total_bytes); | 44 static int msim_send_really_raw(PurpleConnection *gc, const char *buf, int total_bytes); |
45 static gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg); | 45 static gboolean msim_login_challenge(MsimSession *session, MsimMessage *msg); |
46 static const gchar *msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], const gchar *email, const gchar *password, guint *response_len); | 46 static gchar *msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], const gchar *email, const gchar *password, guint *response_len); |
47 | 47 |
48 static gboolean msim_incoming_bm_record_cv(MsimSession *session, MsimMessage *msg); | 48 static gboolean msim_incoming_bm_record_cv(MsimSession *session, MsimMessage *msg); |
49 static gboolean msim_incoming_bm(MsimSession *session, MsimMessage *msg); | 49 static gboolean msim_incoming_bm(MsimSession *session, MsimMessage *msg); |
50 static gboolean msim_incoming_status(MsimSession *session, MsimMessage *msg); | 50 static gboolean msim_incoming_status(MsimSession *session, MsimMessage *msg); |
51 static gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg); | 51 static gboolean msim_incoming_im(MsimSession *session, MsimMessage *msg); |
330 */ | 330 */ |
331 static gboolean | 331 static gboolean |
332 msim_login_challenge(MsimSession *session, MsimMessage *msg) | 332 msim_login_challenge(MsimSession *session, MsimMessage *msg) |
333 { | 333 { |
334 PurpleAccount *account; | 334 PurpleAccount *account; |
335 const gchar *response; | 335 gchar *response; |
336 guint response_len; | 336 guint response_len; |
337 gchar *nc; | 337 gchar *nc; |
338 gsize nc_len; | 338 gsize nc_len; |
339 gboolean ret; | |
339 | 340 |
340 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); | 341 g_return_val_if_fail(MSIM_SESSION_VALID(session), FALSE); |
341 g_return_val_if_fail(msg != NULL, FALSE); | 342 g_return_val_if_fail(msg != NULL, FALSE); |
342 | 343 |
343 g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE); | 344 g_return_val_if_fail(msim_msg_get_binary(msg, "nc", &nc, &nc_len), FALSE); |
361 response_len = 0; | 362 response_len = 0; |
362 response = msim_compute_login_response(nc, account->username, account->password, &response_len); | 363 response = msim_compute_login_response(nc, account->username, account->password, &response_len); |
363 | 364 |
364 g_free(nc); | 365 g_free(nc); |
365 | 366 |
366 return msim_send(session, | 367 ret = msim_send(session, |
367 "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM, | 368 "login2", MSIM_TYPE_INTEGER, MSIM_AUTH_ALGORITHM, |
368 /* This is actually user's email address. */ | 369 /* This is actually user's email address. */ |
369 "username", MSIM_TYPE_STRING, g_strdup(account->username), | 370 "username", MSIM_TYPE_STRING, g_strdup(account->username), |
370 /* GString and gchar * response will be freed in msim_msg_free() in msim_send(). */ | 371 /* GString will be freed in msim_msg_free() in msim_send(). */ |
371 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len), | 372 "response", MSIM_TYPE_BINARY, g_string_new_len(response, response_len), |
372 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION, | 373 "clientver", MSIM_TYPE_INTEGER, MSIM_CLIENT_VERSION, |
373 "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH, | 374 "langid", MSIM_TYPE_INTEGER, MSIM_LANGUAGE_ID_ENGLISH, |
374 "imlang", MSIM_TYPE_STRING, g_strdup(MSIM_LANGUAGE_NAME_ENGLISH), | 375 "imlang", MSIM_TYPE_STRING, g_strdup(MSIM_LANGUAGE_NAME_ENGLISH), |
375 "reconn", MSIM_TYPE_INTEGER, 0, | 376 "reconn", MSIM_TYPE_INTEGER, 0, |
376 "status", MSIM_TYPE_INTEGER, 100, | 377 "status", MSIM_TYPE_INTEGER, 100, |
377 "id", MSIM_TYPE_INTEGER, 1, | 378 "id", MSIM_TYPE_INTEGER, 1, |
378 NULL); | 379 NULL); |
380 | |
381 g_free(response); | |
382 | |
383 return ret; | |
379 } | 384 } |
380 | 385 |
381 /** | 386 /** |
382 * Compute the base64'd login challenge response based on username, password, nonce, and IPs. | 387 * Compute the base64'd login challenge response based on username, password, nonce, and IPs. |
383 * | 388 * |
387 * @param response_len Will be written with response length. | 392 * @param response_len Will be written with response length. |
388 * | 393 * |
389 * @return Binary login challenge response, ready to send to the server. | 394 * @return Binary login challenge response, ready to send to the server. |
390 * Must be g_free()'d when finished. NULL if error. | 395 * Must be g_free()'d when finished. NULL if error. |
391 */ | 396 */ |
392 static const gchar * | 397 static gchar * |
393 msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], | 398 msim_compute_login_response(const gchar nonce[2 * NONCE_SIZE], |
394 const gchar *email, const gchar *password, guint *response_len) | 399 const gchar *email, const gchar *password, guint *response_len) |
395 { | 400 { |
396 PurpleCipherContext *key_context; | 401 PurpleCipherContext *key_context; |
397 PurpleCipher *sha1; | 402 PurpleCipher *sha1; |
486 | 491 |
487 purple_cipher_context_encrypt(rc4, (const guchar *)data, | 492 purple_cipher_context_encrypt(rc4, (const guchar *)data, |
488 data_len, data_out, &data_out_len); | 493 data_len, data_out, &data_out_len); |
489 purple_cipher_context_destroy(rc4); | 494 purple_cipher_context_destroy(rc4); |
490 | 495 |
496 /* TODO: Never assert in a protocol plugin! */ | |
491 g_assert(data_out_len == data_len); | 497 g_assert(data_out_len == data_len); |
492 | 498 |
493 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE | 499 #ifdef MSIM_DEBUG_LOGIN_CHALLENGE |
494 purple_debug_info("msim", "response=<%s>\n", data_out); | 500 purple_debug_info("msim", "response=<%s>\n", data_out); |
495 #endif | 501 #endif |
496 | 502 |
497 *response_len = data_out_len; | 503 *response_len = data_out_len; |
498 | 504 |
499 return (const gchar *)data_out; | 505 return (gchar *)data_out; |
500 } | 506 } |
501 | 507 |
502 /** | 508 /** |
503 * Schedule an IM to be sent once the user ID is looked up. | 509 * Schedule an IM to be sent once the user ID is looked up. |
504 * | 510 * |
1295 /** Handle mail reply checks. */ | 1301 /** Handle mail reply checks. */ |
1296 static void | 1302 static void |
1297 msim_check_inbox_cb(MsimSession *session, MsimMessage *reply, gpointer data) | 1303 msim_check_inbox_cb(MsimSession *session, MsimMessage *reply, gpointer data) |
1298 { | 1304 { |
1299 MsimMessage *body; | 1305 MsimMessage *body; |
1300 GString *notification; | |
1301 guint old_inbox_status; | 1306 guint old_inbox_status; |
1302 guint i, n; | 1307 guint i, n; |
1303 const gchar *froms[5], *tos[5], *urls[5], *subjects[5]; | 1308 const gchar *froms[5], *tos[5], *urls[5], *subjects[5]; |
1304 | 1309 |
1305 /* Information for each new inbox message type. */ | 1310 /* Information for each new inbox message type. */ |
1328 | 1333 |
1329 msim_msg_dump("msim_check_inbox_cb: reply=%s\n", reply); | 1334 msim_msg_dump("msim_check_inbox_cb: reply=%s\n", reply); |
1330 | 1335 |
1331 body = msim_msg_get_dictionary(reply, "body"); | 1336 body = msim_msg_get_dictionary(reply, "body"); |
1332 g_return_if_fail(body != NULL); | 1337 g_return_if_fail(body != NULL); |
1333 | |
1334 notification = g_string_new(""); | |
1335 | 1338 |
1336 old_inbox_status = session->inbox_status; | 1339 old_inbox_status = session->inbox_status; |
1337 | 1340 |
1338 n = 0; | 1341 n = 0; |
1339 | 1342 |
3007 | 3010 |
3008 purple_debug_info("msim", "\n\nTesting MsimMessage\n"); | 3011 purple_debug_info("msim", "\n\nTesting MsimMessage\n"); |
3009 msg = msim_msg_new(NULL); /* Create a new, empty message. */ | 3012 msg = msim_msg_new(NULL); /* Create a new, empty message. */ |
3010 | 3013 |
3011 /* Append some new elements. */ | 3014 /* Append some new elements. */ |
3012 msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len(g_strdup("XXX"), 3)); | 3015 msg = msim_msg_append(msg, "bx", MSIM_TYPE_BINARY, g_string_new_len("XXX", 3)); |
3013 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v1")); | 3016 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v1")); |
3014 msg = msim_msg_append(msg, "k1", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(42)); | 3017 msg = msim_msg_append(msg, "k1", MSIM_TYPE_INTEGER, GUINT_TO_POINTER(42)); |
3015 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v43")); | 3018 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v43")); |
3016 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v52/xxx\\yyy")); | 3019 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v52/xxx\\yyy")); |
3017 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v7")); | 3020 msg = msim_msg_append(msg, "k1", MSIM_TYPE_STRING, g_strdup("v7")); |