From 5e25d0add90786446d6083ac46c8f374ae1463cc Mon Sep 17 00:00:00 2001 From: pbiava Date: Fri, 25 Feb 2011 21:33:51 +0100 Subject: [PATCH 4/5] fix memory leaks thanks Philippe D. --- src/bet_data.c | 199 +++++++++++++++++++++++++++++++----------- src/gsb_assistant_account.c | 1 + src/gsb_file_config.c | 3 + src/gsb_file_load.c | 3 + src/gsb_select_icon.c | 12 ++- src/import.c | 5 +- src/import_csv.c | 3 + src/utils.c | 1 + src/utils_dates.c | 5 +- src/utils_editables.c | 3 + src/utils_files.c | 3 +- src/utils_str.c | 11 ++- 12 files changed, 188 insertions(+), 61 deletions(-) diff --git a/src/bet_data.c b/src/bet_data.c index 0c9f7e5..fbc25d7 100644 --- a/src/bet_data.c +++ b/src/bet_data.c @@ -264,13 +264,19 @@ gboolean bet_data_hist_add_div ( gint account_number, { gchar *key; gchar *sub_key; + gchar *div_number_str, *account_number_str; // only to avoid memory leaks struct_hist_div *shd; + div_number_str = utils_str_itoa ( div_number ); if ( account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL ); + key = g_strconcat ("0:", div_number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( account_number ), ":", - utils_str_itoa ( div_number ), NULL ); + { + account_number_str = utils_str_itoa ( account_number ); + key = g_strconcat ( account_number_str, ":", div_number_str, NULL ); + g_free ( account_number_str ); + } + g_free ( div_number_str ); if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) ) { @@ -342,13 +348,19 @@ void bet_data_insert_div_hist ( struct_hist_div *shd, struct_hist_div *sub_shd ) { gchar *key; gchar *sub_key; + gchar *div_number_str, *account_nb_str; // only to avoid memory leaks struct_hist_div *tmp_shd; + div_number_str = utils_str_itoa ( shd -> div_number ); if ( shd -> account_nb == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( shd -> div_number ), NULL ); + key = g_strconcat ("0:", div_number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( shd -> account_nb ), ":", - utils_str_itoa ( shd -> div_number ), NULL ); + { + account_nb_str = utils_str_itoa ( shd -> account_nb ); + key = g_strconcat ( account_nb_str, ":", div_number_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( div_number_str ); if ( ( tmp_shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) ) { @@ -383,13 +395,19 @@ gboolean bet_data_remove_div_hist ( gint account_number, gint div_number, gint s { gchar *key; char *sub_key; + gchar *div_number_str, *account_number_str; // only to avoid memory leaks struct_hist_div *shd; + div_number_str = utils_str_itoa ( div_number ); if ( account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL ); + key = g_strconcat ("0:", div_number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( account_number ), ":", - utils_str_itoa ( div_number ), NULL ); + { + account_number_str = utils_str_itoa ( account_number ); + key = g_strconcat ( account_number_str, ":", div_number_str, NULL ); + g_free ( account_number_str ); + } + g_free ( div_number_str ); if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) ) { @@ -418,14 +436,20 @@ gboolean bet_data_search_div_hist ( gint account_number, gint div_number, gint s { gchar *key; gchar *sub_key; + gchar *div_number_str, *account_number_str; // only to avoid memory leaks gint origin; struct_hist_div *shd; + div_number_str = utils_str_itoa ( div_number ); if ( account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL ); + key = g_strconcat ("0:", div_number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( account_number ), ":", - utils_str_itoa ( div_number ), NULL ); + { + account_number_str = utils_str_itoa ( account_number ); + key = g_strconcat ( account_number_str, ":", div_number_str, NULL ); + g_free ( account_number_str ); + } + g_free ( div_number_str ); origin = gsb_data_account_get_bet_hist_data ( account_number ); @@ -539,15 +563,21 @@ gchar *bet_data_get_div_name ( gint div_num, gboolean bet_data_get_div_edited ( gint account_number, gint div_number, gint sub_div_nb ) { gchar *key; + gchar *div_number_str, *account_number_str; // only to avoid memory leaks gint origin; struct_hist_div *shd; gboolean edited; + div_number_str = utils_str_itoa ( div_number ); if ( account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL ); + key = g_strconcat ("0:", div_number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( account_number ), ":", - utils_str_itoa ( div_number ), NULL ); + { + account_number_str = utils_str_itoa ( account_number ); + key = g_strconcat ( account_number_str, ":", div_number_str, NULL ); + g_free ( account_number_str ); + } + g_free ( div_number_str ); origin = gsb_data_account_get_bet_hist_data ( account_number ); @@ -589,13 +619,19 @@ gboolean bet_data_set_div_edited ( gint account_nb, gboolean edited ) { gchar *key; + gchar *div_number_str, *account_nb_str; // only to avoid memory leaks struct_hist_div *shd; + div_number_str = utils_str_itoa ( div_number ); if ( account_nb == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL ); + key = g_strconcat ("0:", div_number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( account_nb ), ":", - utils_str_itoa ( div_number ), NULL ); + { + account_nb_str = utils_str_itoa ( account_nb ); + key = g_strconcat ( account_nb_str, ":", div_number_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( div_number_str ); if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) ) { @@ -628,14 +664,20 @@ gboolean bet_data_set_div_edited ( gint account_nb, gsb_real bet_data_hist_get_div_amount ( gint account_nb, gint div_number, gint sub_div_nb ) { gchar *key; + gchar *div_number_str, *account_nb_str; // only to avoid memory leaks struct_hist_div *shd; gsb_real amount; + div_number_str = utils_str_itoa ( div_number ); if ( account_nb == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL ); + key = g_strconcat ("0:", div_number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( account_nb ), ":", - utils_str_itoa ( div_number ), NULL ); + { + account_nb_str = utils_str_itoa ( account_nb ); + key = g_strconcat ( account_nb_str, ":", div_number_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( div_number_str ); if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) ) { @@ -674,13 +716,19 @@ gboolean bet_data_set_div_amount ( gint account_nb, gsb_real amount ) { gchar *key; + gchar *div_number_str, *account_nb_str; // only to avoid memory leaks struct_hist_div *shd; + div_number_str = utils_str_itoa ( div_number ); if ( account_nb == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( div_number ), NULL ); + key = g_strconcat ("0:", div_number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( account_nb ), ":", - utils_str_itoa ( div_number ), NULL ); + { + account_nb_str = utils_str_itoa ( account_nb ); + key = g_strconcat ( account_nb_str, ":", div_number_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( div_number_str ); if ( ( shd = g_hash_table_lookup ( bet_hist_div_list, key ) ) ) { @@ -1167,16 +1215,22 @@ void struct_free_bet_future ( struct_futur_data *scheduled ) gboolean bet_data_future_add_lines ( struct_futur_data *scheduled ) { gchar *key; + gchar *future_number_str, *account_nb_str; // only to avoid memory leaks future_number ++; if ( scheduled -> frequency == 0 ) { + future_number_str = utils_str_itoa ( future_number ); if ( scheduled -> account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( future_number ), NULL ); + key = g_strconcat ("0:", future_number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( scheduled -> account_number ), ":", - utils_str_itoa ( future_number ), NULL ); + { + account_nb_str = utils_str_itoa ( scheduled -> account_number ); + key = g_strconcat ( account_nb_str, ":", future_number_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( future_number_str ); scheduled -> number = future_number; g_hash_table_insert ( bet_future_list, key, scheduled ); @@ -1196,11 +1250,16 @@ gboolean bet_data_future_add_lines ( struct_futur_data *scheduled ) date = gsb_date_copy ( scheduled -> date ); while ( date != NULL && g_date_valid ( date ) ) { + future_number_str = utils_str_itoa ( future_number ); if ( scheduled -> account_number == 0 ) key = g_strconcat ("0:", utils_str_itoa ( future_number ), NULL ); else - key = g_strconcat ( utils_str_itoa ( scheduled -> account_number ), ":", - utils_str_itoa ( future_number ), NULL ); + { + account_nb_str = utils_str_itoa ( scheduled -> account_number ); + key = g_strconcat ( account_nb_str, ":", future_number_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( future_number_str ); if ( mother_row == future_number ) new_sch = scheduled; @@ -1236,16 +1295,22 @@ gboolean bet_data_future_add_lines ( struct_futur_data *scheduled ) gboolean bet_data_future_set_lines_from_file ( struct_futur_data *scheduled ) { gchar *key; + gchar *number_str, *account_nb_str; // only to avoid memory leaks - if ( scheduled -> account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( scheduled -> number ), NULL ); - else - key = g_strconcat ( utils_str_itoa ( scheduled -> account_number ), ":", - utils_str_itoa ( scheduled -> number ), NULL ); + number_str = utils_str_itoa ( scheduled -> number ); + if ( scheduled -> account_number == 0 ) + key = g_strconcat ("0:", number_str, NULL ); + else + { + account_nb_str = utils_str_itoa ( scheduled -> account_number ); + key = g_strconcat ( account_nb_str, ":", number_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( number_str ); - bet_data_future_set_max_number ( scheduled -> number ); + bet_data_future_set_max_number ( scheduled -> number ); - g_hash_table_insert ( bet_future_list, key, scheduled ); + g_hash_table_insert ( bet_future_list, key, scheduled ); return TRUE; } @@ -1557,12 +1622,18 @@ GDate *bet_data_array_get_date_max ( gint account_number ) gboolean bet_data_future_modify_lines ( struct_futur_data *scheduled ) { gchar *key; + gchar *number_str, *account_nb_str; // only to avoid memory leaks + number_str = utils_str_itoa ( scheduled -> number ); if ( scheduled -> account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( scheduled -> number ), NULL ); + key = g_strconcat ("0:", number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( scheduled -> account_number ), ":", - utils_str_itoa ( scheduled -> number ), NULL ); + { + account_nb_str = utils_str_itoa ( scheduled -> account_number ); + key = g_strconcat ( account_nb_str, ":", number_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( number_str ); g_hash_table_replace ( bet_future_list, key, scheduled ); @@ -1582,13 +1653,19 @@ gboolean bet_data_future_modify_lines ( struct_futur_data *scheduled ) struct_futur_data *bet_data_future_get_struct ( gint account_number, gint number ) { gchar *key; + gchar *number_str, *account_nb_str; // only to avoid memory leaks struct_futur_data *scheduled; - if ( account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( number ), NULL ); + number_str = utils_str_itoa ( number ); + if ( scheduled -> account_number == 0 ) + key = g_strconcat ("0:", number_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( account_number ), ":", - utils_str_itoa ( number ), NULL ); + { + account_nb_str = utils_str_itoa ( account_number ); + key = g_strconcat ( account_nb_str, ":", number_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( number_str ); if ( ( scheduled = g_hash_table_lookup ( bet_future_list, key ) ) ) return scheduled; @@ -1651,14 +1728,20 @@ GHashTable *bet_data_transfert_get_list ( void ) gboolean bet_data_transfert_add_line ( struct_transfert_data *transfert ) { gchar *key; + gchar *transfert_nb_str, *account_nb_str; // only to avoid memory leaks transfert_number ++; + transfert_nb_str = utils_str_itoa ( transfert_number ); if ( transfert -> account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( transfert_number ), NULL ); + key = g_strconcat ("0:", transfert_nb_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( transfert -> account_number ), ":", - utils_str_itoa ( transfert_number ), NULL ); + { + account_nb_str = utils_str_itoa ( transfert -> account_number ); + key = g_strconcat ( account_nb_str, ":", transfert_nb_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( transfert_nb_str ); transfert -> number = transfert_number; g_hash_table_insert ( bet_transfert_list, key, transfert ); @@ -1715,12 +1798,18 @@ gboolean bet_data_transfert_remove_line ( gint account_number, gint number ) gboolean bet_data_transfert_set_line_from_file ( struct_transfert_data *transfert ) { gchar *key; + gchar *transfert_nb_str, *account_nb_str; // only to avoid memory leaks + transfert_nb_str = utils_str_itoa ( transfert -> number ); if ( transfert -> account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( transfert -> number ), NULL ); + key = g_strconcat ("0:", transfert_nb_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( transfert -> account_number ), ":", - utils_str_itoa ( transfert -> number ), NULL ); + { + account_nb_str = utils_str_itoa ( transfert -> account_number ); + key = g_strconcat ( account_nb_str, ":", transfert_nb_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( transfert_nb_str ); if ( transfert -> number > transfert_number ) transfert_number = transfert -> number; @@ -1740,12 +1829,18 @@ gboolean bet_data_transfert_set_line_from_file ( struct_transfert_data *transfer gboolean bet_data_transfert_modify_line ( struct_transfert_data *transfert ) { gchar *key; + gchar *transfert_nb_str, *account_nb_str; // only to avoid memory leaks + transfert_nb_str = utils_str_itoa ( transfert -> number ); if ( transfert -> account_number == 0 ) - key = g_strconcat ("0:", utils_str_itoa ( transfert -> number ), NULL ); + key = g_strconcat ("0:", transfert_nb_str, NULL ); else - key = g_strconcat ( utils_str_itoa ( transfert -> account_number ), ":", - utils_str_itoa ( transfert -> number ), NULL ); + { + account_nb_str = utils_str_itoa ( transfert -> account_number ); + key = g_strconcat ( account_nb_str, ":", transfert_nb_str, NULL ); + g_free ( account_nb_str ); + } + g_free ( transfert_nb_str ); g_hash_table_replace ( bet_transfert_list, key, transfert ); diff --git a/src/gsb_assistant_account.c b/src/gsb_assistant_account.c index 84f1caf..83eb348 100644 --- a/src/gsb_assistant_account.c +++ b/src/gsb_assistant_account.c @@ -498,6 +498,7 @@ void gsb_assistant_account_change_account_icon ( GtkWidget *button, gpointer dat { devel_debug ( error -> message ); dialogue_error ( error -> message ); + g_error_free ( error ); } else { diff --git a/src/gsb_file_config.c b/src/gsb_file_config.c index 851552c..6dcfb94 100644 --- a/src/gsb_file_config.c +++ b/src/gsb_file_config.c @@ -1540,7 +1540,10 @@ gchar *gsb_config_get_old_conf_name ( void ) } } else + { dialogue_error ( error -> message ); + g_error_free ( error ); + } if ( g_slist_length ( liste ) == 0 ) return NULL; diff --git a/src/gsb_file_load.c b/src/gsb_file_load.c index f5be275..4c78fb8 100644 --- a/src/gsb_file_load.c +++ b/src/gsb_file_load.c @@ -9027,7 +9027,10 @@ void gsb_file_load_copy_old_file ( gchar *filename, gchar *file_content) file_copy = g_file_new_for_path ( copy_old_filename ); if ( !g_file_copy ( file_ori, file_copy, G_FILE_COPY_OVERWRITE, NULL, NULL, NULL, &error ) ) + { dialogue_error (error -> message ); + g_error_free ( error ); + } } } /* Local Variables: */ diff --git a/src/gsb_select_icon.c b/src/gsb_select_icon.c index bbbf6d9..7a75142 100644 --- a/src/gsb_select_icon.c +++ b/src/gsb_select_icon.c @@ -369,7 +369,10 @@ GtkTreePath * gsb_select_icon_fill_icon_view ( gchar * name_icon ) g_dir_close ( dir ); } else + { dialogue_error ( error -> message ); + g_error_free ( error ); + } if ( tree_path == NULL ) tree_path = gtk_tree_path_new_from_string ( "0" ); @@ -657,7 +660,10 @@ GdkPixbuf *gsb_select_icon_get_default_logo_pixbuf ( void ) (GRISBI_PIXMAPS_DIR, "grisbi-logo.png", NULL), &error ); if ( ! pixbuf ) + { devel_debug ( error -> message ); + g_error_free ( error ); + } if ( gdk_pixbuf_get_width (pixbuf) > LOGO_WIDTH || gdk_pixbuf_get_height (pixbuf) > LOGO_HEIGHT ) @@ -890,6 +896,7 @@ gboolean gsb_select_icon_new_account_icon_from_file ( gint account_number, filename, NULL ); devel_debug ( tmp_str ); dialogue_error ( tmp_str ); + g_error_free ( error ); g_free ( tmp_str ); g_free ( icon ); @@ -909,13 +916,12 @@ GdkPixbuf *gsb_select_icon_change_account_pixbuf ( gint account_number, { GSList *list_tmp; GdkPixbuf *pixbuf; - GError *error = NULL; if ( icon_buffer && icon_buffer -> account_number == account_number ) { - pixbuf = gdk_pixbuf_new_from_file_at_size ( filename , 32, 32, &error ); + pixbuf = gdk_pixbuf_new_from_file_at_size ( filename , 32, 32, NULL ); if ( pixbuf ) { g_object_unref ( icon_buffer -> pixbuf ); @@ -937,7 +943,7 @@ GdkPixbuf *gsb_select_icon_change_account_pixbuf ( gint account_number, if ( icon -> account_number == account_number ) { - pixbuf = gdk_pixbuf_new_from_file_at_size ( filename , 32, 32, &error ); + pixbuf = gdk_pixbuf_new_from_file_at_size ( filename , 32, 32, NULL ); if ( pixbuf ) { g_object_unref ( icon -> pixbuf ); diff --git a/src/import.c b/src/import.c index 1d5ceeb..5543aa1 100644 --- a/src/import.c +++ b/src/import.c @@ -534,6 +534,7 @@ gboolean import_switch_type ( GtkCellRendererText *cell, const gchar *path, if ( ! g_file_get_contents ( nom_fichier, &tmp_str, NULL, &error ) ) { g_print ( _("Unable to read file: %s\n"), error -> message); + g_error_free ( error ); return FALSE; } @@ -688,6 +689,7 @@ gboolean import_select_file ( GtkWidget * button, GtkWidget * assistant ) if ( ! g_file_get_contents ( iterator -> data, &tmp_str, NULL, &error ) ) { g_print ( _("Unable to read file: %s\n"), error -> message); + g_error_free ( error ); return FALSE; } @@ -4386,6 +4388,7 @@ gboolean gsb_import_by_rule ( gint rule ) if ( ! g_file_get_contents ( filename, &pointeur_char, NULL, &error ) ) { g_print ( _("Unable to read file: %s\n"), error -> message); + g_error_free ( error ); i++; continue; } @@ -4677,6 +4680,7 @@ gboolean gsb_import_set_tmp_file ( gchar *filename, { g_free (contenu_fichier); g_print ( _("Unable to create tmp file: %s\n"), error -> message); + g_error_free ( error ); return FALSE; } @@ -4710,7 +4714,6 @@ gboolean gsb_import_gunzip_file ( gchar *filename ) dialogue_error ( tmpstr ); g_free ( file_content); g_error_free (error); - return FALSE; } else diff --git a/src/import_csv.c b/src/import_csv.c index 88b1462..4b1707f 100644 --- a/src/import_csv.c +++ b/src/import_csv.c @@ -1081,6 +1081,7 @@ gboolean import_enter_csv_preview_page ( GtkWidget * assistant ) if ( ! g_file_get_contents ( filename, &tmp_str, &size, &error ) ) { g_print ( _("Unable to read file: %s\n"), error -> message); + g_error_free ( error ); return FALSE; } @@ -1091,6 +1092,7 @@ gboolean import_enter_csv_preview_page ( GtkWidget * assistant ) if ( contents == NULL ) { + g_error_free ( error ); error = NULL; size = 0; bytes_written = 0; @@ -1105,6 +1107,7 @@ gboolean import_enter_csv_preview_page ( GtkWidget * assistant ) if ( bytes_written == 0 ) { g_print ( _("Unable to read file: %s\n"), error -> message); + g_error_free ( error ); return FALSE; } } diff --git a/src/utils.c b/src/utils.c index 16361ef..aeb64ef 100644 --- a/src/utils.c +++ b/src/utils.c @@ -555,6 +555,7 @@ void lance_mailer ( const gchar *uri ) tmp_str = g_strdup_printf ( _("Grisbi was unable to execute a mailer to write at %s.\n" "The error was: %s."), uri, error -> message ); + g_error_free ( error ); dialogue_error_hint ( tmp_str, _("Cannot execute mailer") ); g_free(tmp_str); } diff --git a/src/utils_dates.c b/src/utils_dates.c index 4f45bb2..c84118e 100644 --- a/src/utils_dates.c +++ b/src/utils_dates.c @@ -79,6 +79,7 @@ gchar *gsb_date_today ( void ) date = gdate_today ( ); date_string = gsb_format_gdate ( date ); gsb_date_set_last_date ( date_string ); + g_free ( date_string ); g_date_free ( date ); } return (last_date); @@ -678,8 +679,10 @@ gchar *gsb_date_get_compiled_time ( void ) date = g_date_new_dmy ( atoi ( tab[1] ), mois, atoi ( tab[2] ) ); g_strfreev (tab); + str = gsb_format_gdate ( date ); + g_date_free ( date ); - return gsb_format_gdate ( date ); + return str; } diff --git a/src/utils_editables.c b/src/utils_editables.c index ecfd082..6b15472 100644 --- a/src/utils_editables.c +++ b/src/utils_editables.c @@ -155,7 +155,10 @@ gsb_real gsb_utils_edit_calculate_entry ( GtkWidget *entry ) if ( string && strlen ( string ) ) pointeur = string + strlen ( string ); else + { + g_free ( string ); return total; + } if ( g_utf8_strchr ( string, -1, '-' ) || g_utf8_strchr ( string, -1, '+' ) ) { diff --git a/src/utils_files.c b/src/utils_files.c index d86629a..032db50 100644 --- a/src/utils_files.c +++ b/src/utils_files.c @@ -534,7 +534,6 @@ GSList *utils_files_check_UTF8_validity ( const gchar *contents, gint long_str = 0; gsize size = 0; gsize bytes_written = 0; - GError * error = NULL; gint i = 0; gchar *ptr; @@ -565,7 +564,7 @@ GSList *utils_files_check_UTF8_validity ( const gchar *contents, do { tmp_str = g_convert ( string, long_str, "UTF-8", charset_array[i], - &size, &bytes_written, &error ); + &size, &bytes_written, NULL ); if ( tmp_str ) { result = g_malloc0 ( sizeof ( struct struc_check_encoding ) ); diff --git a/src/utils_str.c b/src/utils_str.c index 8c1e881..729a8a8 100644 --- a/src/utils_str.c +++ b/src/utils_str.c @@ -892,12 +892,16 @@ gchar *utils_str_dtostr ( gdouble number, gint nbre_decimal, gboolean canonical { gchar buffer[G_ASCII_DTOSTR_BUF_SIZE]; gchar *str_number; + gchar *decimal; gchar *format; gint nbre_char; - format = g_strconcat ( "%.", utils_str_itoa ( nbre_decimal ), "f", NULL ); - + decimal = utils_str_itoa ( nbre_decimal ); + format = g_strconcat ( "%.", decimal, "f", NULL ); nbre_char = g_sprintf ( buffer, format, number ); + g_free ( decimal ); + g_free ( format ); + if ( nbre_char > G_ASCII_DTOSTR_BUF_SIZE ) return NULL; @@ -1004,7 +1008,10 @@ gchar *utils_str_incremente_number_from_str ( const gchar *str_number, gint incr new_str_number = utils_str_itoa ( number ); if ( prefix && strlen ( prefix ) > 0 ) + { new_str_number = g_strconcat ( prefix, new_str_number, NULL ); + g_free ( prefix ); + } return new_str_number; } -- 1.7.4