From 38a5db8f83aa9eaf7340c049f91bcf6ed670382b Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 21 Jul 2015 20:39:29 -0400 Subject: [PATCH] GtkQuery: Make API follow GTK+ conversions We generally have const getters for strings, and the two users of this API were promptly leaking the (unexpected) copy they got from gtk_query_get_location and gtk_query_get_text. --- gtk/gtkfilechooserwidget.c | 3 +-- gtk/gtkquery.c | 8 ++++---- gtk/gtkquery.h | 20 ++++++++++---------- gtk/gtksearchenginetracker.c | 5 ++--- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/gtk/gtkfilechooserwidget.c b/gtk/gtkfilechooserwidget.c index cafb5ab418..030d95d94c 100644 --- a/gtk/gtkfilechooserwidget.c +++ b/gtk/gtkfilechooserwidget.c @@ -7272,14 +7272,13 @@ search_setup_widgets (GtkFileChooserWidget *impl) /* if there already is a query, restart it */ if (priv->search_query) { - gchar *query; + const gchar *query; query = gtk_query_get_text (priv->search_query); if (query) { gtk_entry_set_text (GTK_ENTRY (priv->search_entry), query); search_start_query (impl, query); - g_free (query); } else { diff --git a/gtk/gtkquery.c b/gtk/gtkquery.c index a69b278606..bc81b7da3e 100644 --- a/gtk/gtkquery.c +++ b/gtk/gtkquery.c @@ -70,10 +70,10 @@ gtk_query_new (void) } -gchar * +const gchar * gtk_query_get_text (GtkQuery *query) { - return g_strdup (query->priv->text); + return query->priv->text; } void @@ -87,10 +87,10 @@ gtk_query_set_text (GtkQuery *query, query->priv->words = NULL; } -gchar * +const gchar * gtk_query_get_location (GtkQuery *query) { - return g_strdup (query->priv->location_uri); + return query->priv->location_uri; } void diff --git a/gtk/gtkquery.h b/gtk/gtkquery.h index dd3801228a..5027505915 100644 --- a/gtk/gtkquery.h +++ b/gtk/gtkquery.h @@ -49,20 +49,20 @@ struct _GtkQueryClass GObjectClass parent_class; }; -GType gtk_query_get_type (void); +GType gtk_query_get_type (void); -GtkQuery* gtk_query_new (void); +GtkQuery *gtk_query_new (void); -gchar* gtk_query_get_text (GtkQuery *query); -void gtk_query_set_text (GtkQuery *query, - const gchar *text); +const gchar *gtk_query_get_text (GtkQuery *query); +void gtk_query_set_text (GtkQuery *query, + const gchar *text); -gchar* gtk_query_get_location (GtkQuery *query); -void gtk_query_set_location (GtkQuery *query, - const gchar *uri); +const gchar *gtk_query_get_location (GtkQuery *query); +void gtk_query_set_location (GtkQuery *query, + const gchar *uri); -gboolean gtk_query_matches_string (GtkQuery *query, - const gchar *string); +gboolean gtk_query_matches_string (GtkQuery *query, + const gchar *string); G_END_DECLS diff --git a/gtk/gtksearchenginetracker.c b/gtk/gtksearchenginetracker.c index 6c90324513..29edb7f207 100644 --- a/gtk/gtksearchenginetracker.c +++ b/gtk/gtksearchenginetracker.c @@ -320,8 +320,8 @@ static void gtk_search_engine_tracker_start (GtkSearchEngine *engine) { GtkSearchEngineTracker *tracker; - gchar *search_text; - gchar *location_uri; + const gchar *search_text; + const gchar *location_uri; GString *sparql; gboolean recursive; @@ -386,7 +386,6 @@ gtk_search_engine_tracker_start (GtkSearchEngine *engine) get_query_results (tracker, sparql->str, query_callback, g_object_ref (tracker)); g_string_free (sparql, TRUE); - g_free (search_text); } static void