Fix some memory leaks
authorMelvin Hadasht <melvin.hadasht@free.fr>
Tue, 23 Jul 2002 17:17:28 +0000 (17:17 +0000)
committerMelvin Hadasht <melvin.hadasht@free.fr>
Tue, 23 Jul 2002 17:17:28 +0000 (17:17 +0000)
12 files changed:
ChangeLog.claws
configure.in
src/addressbook.c
src/addrgather.c
src/compose.c
src/editaddress.c
src/editgroup.c
src/editldap_basedn.c
src/importldif.c
src/logwindow.c
src/prefs_common.c
src/send.c

index 4c769cf6e8f7f35669675c54cbdd3e73b0a2a29a..42a024d2bf1d3b8d527a662107670359997cf688 100644 (file)
@@ -1,3 +1,24 @@
+2002-07-23 [melvin]    0.8.0claws5
+
+       * src/addressbook.c
+       * src/addrgather.c
+       * src/editaddress.c
+       * src/editgroup.c
+       * src/editldap_basedn.c
+       * src/importldif.c
+       * src/prefs_common.c
+               Fixed few memory leak (gtk_editable_get_chars returns
+               an allocated string)
+       * src/logwindow.c
+               Fixed few memory leak (gtk_editable_get_chars returns
+               an allocated string) and modified a little the log cutting
+               loop.
+       * src/compose.c
+               Replaced a call to an obsolete function gtk_entry_get_text()
+               by gtk_editable_get_chars()
+       * src/send.c
+               Removed a debug printf
+
 2002-07-23 [christoph] 0.8.0claws4
 
        * src/filesel.c
index d41d9a301097a8b4967ca64d48b2c78b0ab3f1b9..f72fd9381f012129aa3411065a181b4a22ad9b3d 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=8
 MICRO_VERSION=0
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws4
+EXTRA_VERSION=claws5
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index e894a0010c9977a5c5dd76848d07e448d9a6ade7..b7ff5dafff2d4b9c8dd5c9fa9af47412a7254d66 100644 (file)
@@ -3256,14 +3256,14 @@ static void addressbook_lup_clicked( GtkButton *button, gpointer data ) {
 #endif
        gchar *sLookup;
 
-       sLookup = gtk_editable_get_chars( GTK_EDITABLE(addrbook.entry), 0, -1 );
-       g_strchomp( sLookup );
-
        if( ! addrbook.treeSelected ) return;
        if( GTK_CTREE_ROW( addrbook.treeSelected )->level == 1 ) return;
 
        obj = gtk_ctree_node_get_row_data( ctree, addrbook.treeSelected );
        if( obj == NULL ) return;
+               
+       sLookup = gtk_editable_get_chars( GTK_EDITABLE(addrbook.entry), 0, -1 );
+       g_strchomp( sLookup );
 
 #ifdef USE_LDAP
        if( obj->type == ADDR_DATASOURCE ) {
@@ -3287,7 +3287,7 @@ static void addressbook_lup_clicked( GtkButton *button, gpointer data ) {
                }
        }
 #endif
-
+       g_free( sLookup );
 }
 
 /* **********************************************************************
index a808977cc8eecbf99e0523fe2a019b82374ced72..f8cabb1d8ce591d64b460db82cbae766c3c260ef 100644 (file)
@@ -175,6 +175,7 @@ static gboolean addrgather_dlg_harvest() {
                addrgather_dlg_status_show(
                        _( "Please select the mail headers to search." ) );
                addrharvest_free( harvester );
+               g_free( name );
                return FALSE;
        }
 
index 2434118b589a2b4a0dd74311801875e2f8314b49..495d89ad7eeb36b17d9e8c2b5478152e025cf44c 100644 (file)
@@ -2646,7 +2646,7 @@ gboolean compose_check_for_valid_recipient(Compose *compose) {
        for(list = compose->header_list; list; list = list->next) {
                gchar *header;
                gchar *entry;
-               header = gtk_entry_get_text(GTK_ENTRY(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry));
+               header = gtk_editable_get_chars(GTK_EDITABLE(GTK_COMBO(((ComposeHeaderEntry *)list->data)->combo)->entry), 0, -1);
                entry = gtk_editable_get_chars(GTK_EDITABLE(((ComposeHeaderEntry *)list->data)->entry), 0, -1);
                g_strstrip(entry);
                if(entry[0] != '\0') {
@@ -2663,6 +2663,7 @@ gboolean compose_check_for_valid_recipient(Compose *compose) {
                                }
                        }
                }
+               g_free(header);
                g_free(entry);
        }
        return recipient_found;
index d1af13e19b9a9cd83160dabe2b2eb3262354a5af..31644e91f83829bc91b562424957256b6aaa169d 100644 (file)
@@ -157,8 +157,11 @@ static void edit_person_set_window_title( gint pageNum ) {
                        sTitle = g_strdup( _title_edit_ );
                }
                else {
-                       sTitle = g_strdup_printf( "%s - %s", _title_edit_,
-                                       gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_name), 0, -1 ) );
+                       gchar *name;
+                       name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_name), 0, -1 );
+                       sTitle = g_strdup_printf( "%s - %s", _title_edit_, name );
+                       g_free( name );
+                                       
                }
                gtk_window_set_title( GTK_WINDOW(personeditdlg.window), sTitle );
                g_free( sTitle );
@@ -260,12 +263,12 @@ static void edit_person_email_delete( gpointer data ) {
 
 static ItemEMail *edit_person_email_edit( gboolean *error, ItemEMail *email ) {
        ItemEMail *retVal = NULL;
-       gchar *sEmail, *sAlias, *sRemarks;
+       gchar *sEmail, *sAlias, *sRemarks, *tEmail;
        *error = TRUE;
-       sEmail = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_email), 0, -1 );
+       tEmail = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_email), 0, -1 );
        sAlias = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_alias), 0, -1 );
        sRemarks = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_remarks), 0, -1 );
-       sEmail = mgu_email_check_empty( sEmail );
+       sEmail = mgu_email_check_empty( tEmail );
        if( sEmail ) {
                if( email == NULL ) {
                        email = addritem_create_item_email();
@@ -279,6 +282,10 @@ static ItemEMail *edit_person_email_edit( gboolean *error, ItemEMail *email ) {
        else {
                edit_person_status_show( _( "An E-Mail address must be supplied." ) );
        }
+       g_free( tEmail );
+       g_free( sEmail );
+       g_free( sAlias );
+       g_free( sRemarks );
        return retVal;
 }
 
@@ -389,12 +396,12 @@ static void edit_person_attrib_delete( gpointer data ) {
 
 static UserAttribute *edit_person_attrib_edit( gboolean *error, UserAttribute *attrib ) {
        UserAttribute *retVal = NULL;
-       gchar *sName, *sValue;
+       gchar *sName, *sValue, *tName, *tValue;
        *error = TRUE;
-       sName = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_atname), 0, -1 );
-       sValue = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_atvalue), 0, -1 );
-       sName = mgu_email_check_empty( sName );
-       sValue = mgu_email_check_empty( sValue );
+       tName = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_atname), 0, -1 );
+       tValue = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_atvalue), 0, -1 );
+       sName = mgu_email_check_empty( tName );
+       sValue = mgu_email_check_empty( tValue );
        if( sName && sValue ) {
                if( attrib == NULL ) {
                        attrib = addritem_create_attribute();
@@ -407,6 +414,10 @@ static UserAttribute *edit_person_attrib_edit( gboolean *error, UserAttribute *a
        else {
                edit_person_status_show( _( "A Name and Value must be supplied." ) );
        }
+       g_free( tName );
+       g_free( sName );
+       g_free( tValue );
+       g_free( sValue );
        return retVal;
 }
 
@@ -973,7 +984,7 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent, I
                return NULL;
        }
 
-       cn = g_strdup( gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_name), 0, -1 ) );
+       cn = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_name), 0, -1 );
        if( person ) {
                /* Update email/attribute list */
                addrbook_update_address_list( abf, person, listEMail );
@@ -993,13 +1004,17 @@ ItemPerson *addressbook_edit_person( AddressBookFile *abf, ItemFolder *parent, I
 
        if( ! cancelled ) {
                /* Set person stuff */
+               gchar *name;
                addritem_person_set_common_name( person, cn );
-               addritem_person_set_first_name( person,
-                       gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_first), 0, -1 ) );
-               addritem_person_set_last_name( person,
-                       gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_last), 0, -1 ) );
-               addritem_person_set_nick_name( person,
-                       gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_nick), 0, -1 ) );
+               name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_first), 0, -1 ); 
+               addritem_person_set_first_name( person, name );
+               g_free( name );
+               name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_last), 0, -1 );
+               addritem_person_set_last_name( person, name );
+               g_free( name );
+               name = gtk_editable_get_chars( GTK_EDITABLE(personeditdlg.entry_nick), 0, -1 );
+               addritem_person_set_nick_name( person, name );
+               g_free( name );
        }
        g_free( cn );
 
index a1ca39b1fa08f6213212bbbb8c5de5a61a5599ed..e5b2a0459a4fb011f147394eb1eef5a81091bcaa 100644 (file)
@@ -88,7 +88,7 @@ static void edit_group_status_show( gchar *msg ) {
 }
 
 static void edit_group_ok(GtkWidget *widget, gboolean *cancelled) {
-       gchar *sName = g_strdup( gtk_editable_get_chars( GTK_EDITABLE(groupeditdlg.entry_name), 0, -1 ) );
+       gchar *sName = gtk_editable_get_chars( GTK_EDITABLE(groupeditdlg.entry_name), 0, -1 );
        gboolean errFlag = TRUE;
        if( sName ) {
                g_strstrip( sName );
@@ -428,6 +428,7 @@ static GList *edit_group_build_email_list() {
 ItemGroup *addressbook_edit_group( AddressBookFile *abf, ItemFolder *parent, ItemGroup *group ) {
        static gboolean cancelled;
        GList *listEMail = NULL;
+       gchar *name;
 
        if (!groupeditdlg.window)
                addressbook_edit_group_create(&cancelled);
@@ -479,8 +480,9 @@ ItemGroup *addressbook_edit_group( AddressBookFile *abf, ItemFolder *parent, Ite
                /* Create new person and email list */
                group = addrbook_add_group_list( abf, parent, listEMail );
        }
-       addritem_group_set_name( group, gtk_editable_get_chars( GTK_EDITABLE(groupeditdlg.entry_name), 0, -1 ) );
-
+       name = gtk_editable_get_chars( GTK_EDITABLE(groupeditdlg.entry_name), 0, -1 ); 
+       addritem_group_set_name( group, name );
+       g_free( name );
        listEMail = NULL;
        return group;
 }
index a2aa21c34b95035b78c4b5ec0b7de04acf4c4b86..6cb32e9d296eb15f17e39acaa5ed30b65c2037ee 100644 (file)
@@ -313,7 +313,7 @@ gchar *edit_ldap_basedn_selection( const gchar *hostName, const gint port, gchar
        if( ldapedit_basedn_cancelled ) return NULL;
        if( ldapedit_basedn_bad_server ) return NULL;
 
-       retVal = g_strdup( gtk_editable_get_chars( GTK_EDITABLE(ldapedit_basedn.basedn_entry), 0, -1 ) );
+       retVal = gtk_editable_get_chars( GTK_EDITABLE(ldapedit_basedn.basedn_entry), 0, -1 );
        g_strchomp( retVal ); g_strchug( retVal );
        if( *retVal == '\0' ) {
                g_free( retVal );
index ae6a96a205d96739d2f60c484ca7ff9a04127cf8..e0ed78314f7161c7c43621269594f2e87f3f76f4 100644 (file)
@@ -225,7 +225,7 @@ static void imp_ldif_modify_pressed( GtkWidget *widget, gpointer data ) {
        rec = gtk_clist_get_row_data( clist, impldif_dlg.rowIndSelect );
 
        g_free( rec->userName );
-       rec->userName = g_strdup( gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_attrib), 0, -1 ) );
+       rec->userName = gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_attrib), 0, -1 );
        rec->selected = gtk_toggle_button_get_active( GTK_TOGGLE_BUTTON( impldif_dlg.check_select) );
        imp_ldif_update_row( clist );
        gtk_clist_select_row( clist, row, 0 );
@@ -328,10 +328,13 @@ static gboolean imp_ldif_file_move() {
 static void imp_ldif_finish_show() {
        gchar *recs;
        gchar *sMsg;
+       gchar *name;
 
        recs = g_strdup_printf( "%d", _ldifFile_->importCount );
-       gtk_label_set_text( GTK_LABEL(impldif_dlg.labelBook),
-               gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_entry), 0, -1 ) );
+
+       name =  gtk_editable_get_chars( GTK_EDITABLE(impldif_dlg.name_entry), 0, -1 );
+       gtk_label_set_text( GTK_LABEL(impldif_dlg.labelBook), name );
+       g_free( name );
        gtk_label_set_text( GTK_LABEL(impldif_dlg.labelFile), _ldifFile_->path );
        gtk_label_set_text( GTK_LABEL(impldif_dlg.labelRecords), recs );
        g_free( recs );
index 56356182648769de6394057c8c2e250c50fb927d..9412f2270857fab4fa19d2335138c817d5fca635 100644 (file)
@@ -160,6 +160,7 @@ static void key_pressed(GtkWidget *widget, GdkEventKey *event,
                gtk_widget_hide(logwin->window);
 }
 
+#define LOG_AVG_LINE_LEN 80
 void log_window_clear(GtkWidget *text)
 {
         guint length;
@@ -170,16 +171,22 @@ void log_window_clear(GtkWidget *text)
        debug_print(_("Log window length: %u\n"), length);
        
        if (length > prefs_common.loglength) {
+               gchar *lf;
                /* find the end of the first line after the cut off
                 * point */
                        point = length - prefs_common.loglength;
-               gtk_text_set_point (GTK_TEXT (text), point);
-               str = gtk_editable_get_chars (GTK_EDITABLE (text),
-                                             point, point + 1);
+               
+               do {
+                       str = gtk_editable_get_chars (GTK_EDITABLE (text),
+                                       point, point + LOG_AVG_LINE_LEN);
+                       if ((lf = strchr(str, '\n')) != NULL)
+                               point += lf - str;
+                       else 
+                               point += LOG_AVG_LINE_LEN;
+                       g_free(str);
+               } while (lf == NULL);
+                               
                gtk_text_freeze (GTK_TEXT (text));
-               while(str && *str != '\n')
-                      str = gtk_editable_get_chars (GTK_EDITABLE (text),
-                                                    ++point, point + 2);
                
                /* erase the text */
                gtk_text_set_point (GTK_TEXT (text), 0);
index e67bfd54818c19362915947e91f35b0157367790..b2c8cf106a8ae6a0d381e36372af67e902718dbb 100644 (file)
@@ -3025,6 +3025,7 @@ static void date_format_entry_on_change(GtkEditable *editable,
        if (text)
                strftime(buffer, sizeof buffer, text, cal_time); 
        gtk_label_set_text(example, buffer);
+       g_free(text);
 }
 
 static void date_format_select_row(GtkWidget *date_format_list, gint row,
index 9ef291a6b045889b82744e8a369885896c972048..d19a241ef66f8e2499ab05ade63a75f74e84bbf0 100644 (file)
@@ -83,8 +83,6 @@ gint send_message(const gchar *file, PrefsAccount *ac_prefs, GSList *to_list)
                return -1;
        }
 
-       printf("account: %p\n", ac_prefs);
-
        if (ac_prefs->use_mail_command && ac_prefs->mail_command &&
            (*ac_prefs->mail_command)) {
                val = send_message_local(ac_prefs->mail_command, fp);