[gnome-control-center/gnome-3-2] color: Don't return pointer to local variables
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-control-center/gnome-3-2] color: Don't return pointer to local variables
- Date: Thu, 20 Oct 2011 16:00:26 +0000 (UTC)
commit 1c621fc47be0744d05c76abda1650bc99afd7e60
Author: Bastien Nocera <hadess hadess net>
Date: Thu Oct 20 15:46:32 2011 +0100
color: Don't return pointer to local variables
We were returning the address of a variable allocated on the stack
inside the function to outside.
panels/color/cc-color-panel.c | 31 ++++++++++++++++---------------
1 files changed, 16 insertions(+), 15 deletions(-)
---
diff --git a/panels/color/cc-color-panel.c b/panels/color/cc-color-panel.c
index 2efebc0..3ff7f62 100644
--- a/panels/color/cc-color-panel.c
+++ b/panels/color/cc-color-panel.c
@@ -1449,29 +1449,32 @@ static GtkTreeIter *
get_iter_for_profile (GtkTreeModel *model, CdProfile *profile, GtkTreeIter *parent)
{
const gchar *id;
- GtkTreeIter iter_tmp;
gboolean ret;
- GtkTreeIter *iter = NULL;
+ GtkTreeIter iter;
CdProfile *profile_tmp;
/* get first element */
- ret = gtk_tree_model_iter_children (model, &iter_tmp, parent);
+ ret = gtk_tree_model_iter_children (model, &iter, parent);
if (!ret)
- goto out;
+ return NULL;
/* remove the other elements */
id = cd_profile_get_id (profile);
- do
+ while (ret)
{
- gtk_tree_model_get (model, &iter_tmp,
+ gtk_tree_model_get (model, &iter,
GCM_PREFS_COLUMN_PROFILE, &profile_tmp,
-1);
if (g_strcmp0 (id, cd_profile_get_id (profile_tmp)) == 0)
- iter = &iter_tmp;
+ {
+ g_object_unref (profile_tmp);
+ return gtk_tree_iter_copy (&iter);
+ }
g_object_unref (profile_tmp);
- } while (iter == NULL && gtk_tree_model_iter_next (model, &iter_tmp));
-out:
- return iter;
+ ret = gtk_tree_model_iter_next (model, &iter);
+ }
+
+ return NULL;
}
static void
@@ -1613,12 +1616,9 @@ skip:
iter_tmp_p = get_iter_for_profile (GTK_TREE_MODEL (priv->list_store_devices),
profile_tmp, iter);
if (iter_tmp_p == NULL)
- {
- gtk_tree_store_append (priv->list_store_devices, &iter_tmp, iter);
- iter_tmp_p = &iter_tmp;
- }
+ gtk_tree_store_append (priv->list_store_devices, &iter_tmp, iter);
- gtk_tree_store_set (priv->list_store_devices, iter_tmp_p,
+ gtk_tree_store_set (priv->list_store_devices, iter_tmp_p ? iter_tmp_p : &iter_tmp,
GCM_PREFS_COLUMN_DEVICE, device,
GCM_PREFS_COLUMN_PROFILE, profile_tmp,
GCM_PREFS_COLUMN_DEVICE_PATH, cd_device_get_object_path (device),
@@ -1628,6 +1628,7 @@ skip:
GCM_PREFS_COLUMN_RADIO_VISIBLE, TRUE,
GCM_PREFS_COLUMN_RADIO_ACTIVE, i==0,
-1);
+ gtk_tree_iter_free (iter_tmp_p);
g_free (title_tmp);
g_free (sort_tmp);
g_string_free (date_tmp, TRUE);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]