comparison libpurple/protocols/bonjour/jabber.c @ 15811:71b017348c39

plug some memory leaks
author Stu Tomlinson <stu@nosnilmot.com>
date Sat, 17 Mar 2007 17:55:22 +0000
parents 5fe8042783c1
children 32c366eeeb99
comparison
equal deleted inserted replaced
15810:6c686942a227 15811:71b017348c39
529 xmlnode *message_html_body_node = NULL; 529 xmlnode *message_html_body_node = NULL;
530 xmlnode *message_html_body_font_node = NULL; 530 xmlnode *message_html_body_font_node = NULL;
531 xmlnode *message_x_node = NULL; 531 xmlnode *message_x_node = NULL;
532 GaimBuddy *gb = NULL; 532 GaimBuddy *gb = NULL;
533 BonjourBuddy *bb = NULL; 533 BonjourBuddy *bb = NULL;
534 char *conv_message = NULL;
535 GaimConversation *conversation = NULL; 534 GaimConversation *conversation = NULL;
536 char *message_from_ui = NULL; 535 char *message_from_ui = NULL;
537 char *stripped_message = NULL; 536 char *stripped_message = NULL;
537 gint ret;
538 538
539 gb = gaim_find_buddy(data->account, to); 539 gb = gaim_find_buddy(data->account, to);
540 if (gb == NULL) 540 if (gb == NULL)
541 /* You can not send a message to an offline buddy */ 541 /* You can not send a message to an offline buddy */
542 return -10000; 542 return -10000;
545 545
546 /* Enclose the message from the UI within a "font" node */ 546 /* Enclose the message from the UI within a "font" node */
547 message_body_node = xmlnode_new("body"); 547 message_body_node = xmlnode_new("body");
548 stripped_message = gaim_markup_strip_html(body); 548 stripped_message = gaim_markup_strip_html(body);
549 xmlnode_insert_data(message_body_node, stripped_message, strlen(stripped_message)); 549 xmlnode_insert_data(message_body_node, stripped_message, strlen(stripped_message));
550 g_free(stripped_message);
550 551
551 message_from_ui = g_strconcat("<font>", body, "</font>", NULL); 552 message_from_ui = g_strconcat("<font>", body, "</font>", NULL);
552 message_html_body_font_node = xmlnode_from_str(message_from_ui, strlen(message_from_ui)); 553 message_html_body_font_node = xmlnode_from_str(message_from_ui, strlen(message_from_ui));
554 g_free(message_from_ui);
553 555
554 message_html_body_node = xmlnode_new("body"); 556 message_html_body_node = xmlnode_new("body");
555 xmlnode_insert_child(message_html_body_node, message_html_body_font_node); 557 xmlnode_insert_child(message_html_body_node, message_html_body_font_node);
556 558
557 message_html_node = xmlnode_new("html"); 559 message_html_node = xmlnode_new("html");
569 xmlnode_insert_child(message_node, message_body_node); 571 xmlnode_insert_child(message_node, message_body_node);
570 xmlnode_insert_child(message_node, message_html_node); 572 xmlnode_insert_child(message_node, message_html_node);
571 xmlnode_insert_child(message_node, message_x_node); 573 xmlnode_insert_child(message_node, message_x_node);
572 574
573 message = xmlnode_to_str(message_node, &message_length); 575 message = xmlnode_to_str(message_node, &message_length);
576 xmlnode_free(message_node);
574 577
575 /* Check if there is a previously open conversation */ 578 /* Check if there is a previously open conversation */
576 if (bb->conversation == NULL) 579 if (bb->conversation == NULL)
577 { 580 {
578 bb->conversation = g_new(BonjourJabberConversation, 1); 581 bb->conversation = g_new(BonjourJabberConversation, 1);
589 /* Start the stream */ 592 /* Start the stream */
590 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1) 593 if (send(bb->conversation->socket, DOCTYPE, strlen(DOCTYPE), 0) == -1)
591 { 594 {
592 gaim_debug_error("bonjour", "Unable to start a conversation\n"); 595 gaim_debug_error("bonjour", "Unable to start a conversation\n");
593 gaim_debug_warning("bonjour", "send error: %s\n", strerror(errno)); 596 gaim_debug_warning("bonjour", "send error: %s\n", strerror(errno));
594 conv_message = g_strdup(_("Unable to send the message, the conversation couldn't be started."));
595 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, bb->name, data->account); 597 conversation = gaim_find_conversation_with_account(GAIM_CONV_TYPE_IM, bb->name, data->account);
596 gaim_conversation_write(conversation, NULL, conv_message, GAIM_MESSAGE_SYSTEM, time(NULL)); 598 gaim_conversation_write(conversation, NULL,
599 _("Unable to send the message, the conversation couldn't be started."),
600 GAIM_MESSAGE_SYSTEM, time(NULL));
597 close(bb->conversation->socket); 601 close(bb->conversation->socket);
598 gaim_input_remove(bb->conversation->watcher_id); 602 gaim_input_remove(bb->conversation->watcher_id);
599 603
600 /* Free all the data related to the conversation */ 604 /* Free all the data related to the conversation */
601 g_free(bb->conversation->buddy_name); 605 g_free(bb->conversation->buddy_name);
602 g_free(bb->conversation); 606 g_free(bb->conversation);
603 bb->conversation = NULL; 607 bb->conversation = NULL;
608 g_free(message);
604 return 0; 609 return 0;
605 } 610 }
606 611
607 bb->conversation->stream_started = TRUE; 612 bb->conversation->stream_started = TRUE;
608 } 613 }
609 614
610 /* Send the message */ 615 /* Send the message */
611 if (_send_data(bb->conversation->socket, message) == -1) 616 ret = _send_data(bb->conversation->socket, message) == -1;
617 g_free(message);
618
619 if (ret == -1)
612 return -10000; 620 return -10000;
613 621
614 return 1; 622 return 1;
615 } 623 }
616 624