comparison pidgin/plugins/spellchk.c @ 22453:34b8d1107b06

Fix multiple memory leaks
author Stu Tomlinson <stu@nosnilmot.com>
date Wed, 12 Mar 2008 01:38:51 +0000
parents 0503cd74cb56
children 1767bf74b95c
comparison
equal deleted inserted replaced
22452:bb7b11ca28ca 22453:34b8d1107b06
62 struct _spellchk { 62 struct _spellchk {
63 GtkTextView *view; 63 GtkTextView *view;
64 GtkTextMark *mark_insert_start; 64 GtkTextMark *mark_insert_start;
65 GtkTextMark *mark_insert_end; 65 GtkTextMark *mark_insert_end;
66 66
67 const gchar *word; 67 gchar *word;
68 gboolean inserting; 68 gboolean inserting;
69 gboolean ignore_correction; 69 gboolean ignore_correction;
70 gboolean ignore_correction_on_send; 70 gboolean ignore_correction_on_send;
71 gint pos; 71 gint pos;
72 }; 72 };
263 outword = g_strdup(good); 263 outword = g_strdup(good);
264 264
265 g_value_unset(&val1); 265 g_value_unset(&val1);
266 g_value_unset(&val2); 266 g_value_unset(&val2);
267 267
268 g_free(lowerword);
268 g_free(foldedword); 269 g_free(foldedword);
269 return outword; 270 return outword;
270 } 271 }
271 272
272 g_value_unset(&val1); 273 g_value_unset(&val1);
273 g_free(tmpbad); 274 g_free(tmpbad);
274 275
275 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter)); 276 } while (gtk_tree_model_iter_next(GTK_TREE_MODEL(model), &iter));
276 } 277 }
278 g_free(lowerword);
277 g_free(foldedword); 279 g_free(foldedword);
278 280
279 return NULL; 281 return NULL;
280 } 282 }
281 283
290 292
291 g_signal_handlers_disconnect_matched(buffer, 293 g_signal_handlers_disconnect_matched(buffer,
292 G_SIGNAL_MATCH_DATA, 294 G_SIGNAL_MATCH_DATA,
293 0, 0, NULL, NULL, 295 0, 0, NULL, NULL,
294 spell); 296 spell);
297 g_free(spell->word);
295 g_free(spell); 298 g_free(spell);
296 } 299 }
297 300
298 /* Pango doesn't know about the "'" character. Let's fix that. */ 301 /* Pango doesn't know about the "'" character. Let's fix that. */
299 static gboolean 302 static gboolean
438 gtk_text_iter_forward_char(&end); 441 gtk_text_iter_forward_char(&end);
439 442
440 /* Move backwards to the beginning of the word. */ 443 /* Move backwards to the beginning of the word. */
441 spellchk_backward_word_start(&start); 444 spellchk_backward_word_start(&start);
442 445
446 g_free(spell->word);
443 spell->word = gtk_text_iter_get_text(&start, &end); 447 spell->word = gtk_text_iter_get_text(&start, &end);
444 448
445 /* Hack because otherwise typing things like U.S. gets difficult 449 /* Hack because otherwise typing things like U.S. gets difficult
446 * if you have 'u' -> 'you' set as a correction... 450 * if you have 'u' -> 'you' set as a correction...
447 * 451 *
482 g_free(tmp); 486 g_free(tmp);
483 return TRUE; 487 return TRUE;
484 } 488 }
485 g_free(tmp); 489 g_free(tmp);
486 490
491 g_free(spell->word);
487 spell->word = NULL; 492 spell->word = NULL;
488 493
489 return replaced; 494 return replaced;
490 } 495 }
491 496
502 if (spell->inserting == TRUE) 507 if (spell->inserting == TRUE)
503 return; 508 return;
504 509
505 spell->inserting = TRUE; 510 spell->inserting = TRUE;
506 511
512 g_free(spell->word);
507 spell->word = NULL; 513 spell->word = NULL;
508 514
509 gtk_text_buffer_move_mark(buffer, spell->mark_insert_start, iter); 515 gtk_text_buffer_move_mark(buffer, spell->mark_insert_start, iter);
510 } 516 }
511 517
559 mark = gtk_text_buffer_get_insert(buffer); 565 mark = gtk_text_buffer_get_insert(buffer);
560 gtk_text_buffer_get_iter_at_mark(buffer, &pos, mark); 566 gtk_text_buffer_get_iter_at_mark(buffer, &pos, mark);
561 place = gtk_text_iter_get_offset(&pos); 567 place = gtk_text_iter_get_offset(&pos);
562 568
563 if ((place + 1) != spell->pos) { 569 if ((place + 1) != spell->pos) {
570 g_free(spell->word);
564 spell->word = NULL; 571 spell->word = NULL;
565 return; 572 return;
566 } 573 }
567 574
568 gtk_text_buffer_get_iter_at_mark(buffer, &start2, spell->mark_insert_start); 575 gtk_text_buffer_get_iter_at_mark(buffer, &start2, spell->mark_insert_start);
572 gtk_text_buffer_insert(buffer, &start2, spell->word, -1); 579 gtk_text_buffer_insert(buffer, &start2, spell->word, -1);
573 spell->ignore_correction = TRUE; 580 spell->ignore_correction = TRUE;
574 spell->ignore_correction_on_send = TRUE; 581 spell->ignore_correction_on_send = TRUE;
575 582
576 spell->inserting = FALSE; 583 spell->inserting = FALSE;
584 g_free(spell->word);
577 spell->word = NULL; 585 spell->word = NULL;
578 } 586 }
579 587
580 static void 588 static void
581 message_send_cb(GtkWidget *widget, spellchk *spell) 589 message_send_cb(GtkWidget *widget, spellchk *spell)