comparison libpurple/protocols/bonjour/jabber.c @ 18651:b981d3c39d0b

Fix memory leak (also includes an efficiency rearrangement for the xmlnode parsing that has been sitting on my machine for a while).
author Daniel Atallah <daniel.atallah@gmail.com>
date Thu, 26 Jul 2007 15:21:23 +0000
parents 1faa319ab4c3
children 316be7e715c6
comparison
equal deleted inserted replaced
18650:648545b2c1f1 18651:b981d3c39d0b
348 gint message_length; 348 gint message_length;
349 PurpleBuddy *pb = data; 349 PurpleBuddy *pb = data;
350 PurpleAccount *account = pb->account; 350 PurpleAccount *account = pb->account;
351 BonjourBuddy *bb = pb->proto_data; 351 BonjourBuddy *bb = pb->proto_data;
352 gboolean closed_conversation = FALSE; 352 gboolean closed_conversation = FALSE;
353 xmlnode *message_node;
354 353
355 /* Read the data from the socket */ 354 /* Read the data from the socket */
356 if ((message_length = _read_data(socket, &message)) == -1) { 355 if ((message_length = _read_data(socket, &message)) == -1) {
357 /* There have been an error reading from the socket */ 356 /* There have been an error reading from the socket */
358 if (errno != EAGAIN) { 357 if (errno != EAGAIN) {
371 while (g_ascii_iscntrl(message[message_length - 1])) { 370 while (g_ascii_iscntrl(message[message_length - 1])) {
372 message[message_length - 1] = '\0'; 371 message[message_length - 1] = '\0';
373 message_length--; 372 message_length--;
374 } 373 }
375 } 374 }
376
377 /* Parse the message into an XMLnode for analysis */
378 message_node = xmlnode_from_str(message, strlen(message));
379 375
380 /* 376 /*
381 * Check that this is not the end of the conversation. This is 377 * Check that this is not the end of the conversation. This is
382 * using a magic string, but xmlnode won't play nice when just 378 * using a magic string, but xmlnode won't play nice when just
383 * parsing an end tag 379 * parsing an end tag
394 if (conv != NULL) { 390 if (conv != NULL) {
395 char *tmp = g_strdup_printf(_("%s has closed the conversation."), pb->name); 391 char *tmp = g_strdup_printf(_("%s has closed the conversation."), pb->name);
396 purple_conversation_write(conv, NULL, tmp, PURPLE_MESSAGE_SYSTEM, time(NULL)); 392 purple_conversation_write(conv, NULL, tmp, PURPLE_MESSAGE_SYSTEM, time(NULL));
397 g_free(tmp); 393 g_free(tmp);
398 } 394 }
399 } else if (message_node != NULL) {
400 /* Parse the message to get the data and send to the ui */
401 _jabber_parse_and_write_message_to_ui(message_node, account->gc, pb);
402 } else { 395 } else {
403 /* TODO: Deal with receiving only a partial message */ 396 xmlnode *message_node;
397
398 /* Parse the message into an XMLnode for analysis */
399 message_node = xmlnode_from_str(message, strlen(message));
400
401 if (message_node != NULL) {
402 /* Parse the message to get the data and send to the ui */
403 _jabber_parse_and_write_message_to_ui(message_node, account->gc, pb);
404 xmlnode_free(message_node);
405 } else {
406 /* TODO: Deal with receiving only a partial message */
407 }
404 } 408 }
405 409
406 g_free(message); 410 g_free(message);
407 if (message_node != NULL)
408 xmlnode_free(message_node);
409 } 411 }
410 412
411 struct _stream_start_data { 413 struct _stream_start_data {
412 char *msg; 414 char *msg;
413 PurpleInputFunction tx_handler_cb; 415 PurpleInputFunction tx_handler_cb;
636 _connected_to_buddy(gpointer data, gint source, const gchar *error) 638 _connected_to_buddy(gpointer data, gint source, const gchar *error)
637 { 639 {
638 PurpleBuddy *pb = data; 640 PurpleBuddy *pb = data;
639 BonjourBuddy *bb = pb->proto_data; 641 BonjourBuddy *bb = pb->proto_data;
640 int len, ret; 642 int len, ret;
641 char *stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), purple_buddy_get_name(pb)); 643 char *stream_start;
642 644
643 bb->conversation->connect_data = NULL; 645 bb->conversation->connect_data = NULL;
644 646
645 if (source < 0) { 647 if (source < 0) {
646 PurpleConversation *conv; 648 PurpleConversation *conv;
657 bonjour_jabber_close_conversation(bb->conversation); 659 bonjour_jabber_close_conversation(bb->conversation);
658 bb->conversation = NULL; 660 bb->conversation = NULL;
659 return; 661 return;
660 } 662 }
661 663
664 stream_start = g_strdup_printf(DOCTYPE, purple_account_get_username(pb->account), purple_buddy_get_name(pb));
662 len = strlen(stream_start); 665 len = strlen(stream_start);
663 666
664 /* Start the stream and send queued messages */ 667 /* Start the stream and send queued messages */
665 ret = send(source, stream_start, len, 0); 668 ret = send(source, stream_start, len, 0);
666 669