From a30c4b9e94943b2fa70e38be197529f84fbe6ad5 Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Thu, 3 Feb 2000 01:42:51 +0000 Subject: Argh, decided not to return a string that must be freed from gtk_file_selection_get_filename after all, as that would cause memory leaks in all apps that use it unless they specifically checked fot the GTk+ version. gtk_file_selection_get_filename returns the filename in the C runtime encoding. It calls g_filename_from_utf8, but copies the returned string to a static buffer, which is returned. I think this is better than returning the result from g_filename_from_utf8 directly, which would mean all apps that use it would have to free the return value. Or should this function care about this issue at all? Maybe a new function with clearly defined semantics. --- gtk/gtkfilesel.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'gtk/gtkfilesel.c') diff --git a/gtk/gtkfilesel.c b/gtk/gtkfilesel.c index d3a1904364..e792948640 100644 --- a/gtk/gtkfilesel.c +++ b/gtk/gtkfilesel.c @@ -728,9 +728,10 @@ gtk_file_selection_set_filename (GtkFileSelection *filesel, gchar* gtk_file_selection_get_filename (GtkFileSelection *filesel) { - static char nothing[2] = ""; - char *text; + static gchar nothing[2] = ""; + static gchar something[MAXPATHLEN*2]; char *filename; + char *text; g_return_val_if_fail (filesel != NULL, nothing); g_return_val_if_fail (GTK_IS_FILE_SELECTION (filesel), nothing); @@ -741,8 +742,10 @@ gtk_file_selection_get_filename (GtkFileSelection *filesel) text = gtk_entry_get_text (GTK_ENTRY (filesel->selection_entry)); if (text) { - filename = cmpl_completion_fullname (text, filesel->cmpl_state); - return g_filename_from_utf8 (filename); + filename = g_filename_from_utf8 (cmpl_completion_fullname (text, filesel->cmpl_state)); + strncpy (something, filename, sizeof (something)); + g_free (filename); + return something; } return nothing; -- cgit v1.2.1