[gitg] Use GPtrArray instead of manually g_realloc
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [gitg] Use GPtrArray instead of manually g_realloc
- Date: Wed, 13 Jan 2010 08:24:53 +0000 (UTC)
commit e373c02658399e22dc4883f0a81f0d34406de48e
Author: Jesse van den Kieboom <jesse vandenkieboom epfl ch>
Date: Wed Jan 13 09:23:42 2010 +0100
Use GPtrArray instead of manually g_realloc
This fixes bug #606791 where the wrong memory was realloced.
gitg/gitg-repository.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
---
diff --git a/gitg/gitg-repository.c b/gitg/gitg-repository.c
index bffb939..2e01631 100644
--- a/gitg/gitg-repository.c
+++ b/gitg/gitg-repository.c
@@ -1613,13 +1613,14 @@ gitg_repository_get_remotes (GitgRepository *repository)
GitgConfig *config = gitg_config_new (repository);
gchar *ret = gitg_config_get_value_regex (config, "remote\\..*\\.url");
- gchar **remotes = g_malloc (sizeof (gchar *));
- remotes[0] = NULL;
+ GPtrArray *remotes = g_ptr_array_new ();
if (!ret)
{
+ g_ptr_array_add (remotes, NULL);
g_object_unref (config);
- return remotes;
+
+ return (gchar **)g_ptr_array_free (remotes, FALSE);
}
gchar **lines = g_strsplit(ret, "\n", -1);
@@ -1636,17 +1637,18 @@ gitg_repository_get_remotes (GitgRepository *repository)
{
gchar *name = g_match_info_fetch (info, 1);
- remotes = g_realloc (ret, sizeof(gchar *) * (++num + 1));
- remotes[num - 1] = name;
+ g_ptr_array_add (remotes, name);
}
g_match_info_free (info);
++ptr;
}
- remotes[num] = NULL;
+ /* NULL terminate */
+ g_ptr_array_add (remotes, NULL);
g_object_unref (config);
- return remotes;
+
+ return (gchar **)g_ptr_array_free (remotes, FALSE);
}
gboolean
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]