From: Matthias Clasen Date: Tue, 5 Apr 2005 04:09:49 +0000 (+0000) Subject: Avoid memory leaks in borderline cases. (#172612, Morten Welinder) X-Git-Tag: GLIB_2_7_0~88 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4fe1315d5e46f3d5feb950f81dd49dc1b16fa7cd;p=platform%2Fupstream%2Fglib.git Avoid memory leaks in borderline cases. (#172612, Morten Welinder) 2005-04-05 Matthias Clasen * glib/gfileutils.c (get_contents_stdio): Avoid memory leaks in borderline cases. (#172612, Morten Welinder) --- diff --git a/ChangeLog b/ChangeLog index ee22fdd..7bc0276 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-04-05 Matthias Clasen + + * glib/gfileutils.c (get_contents_stdio): Avoid memory + leaks in borderline cases. (#172612, Morten Welinder) + 2005-04-04 Matthias Clasen * glib/gconvert.c: Clarify docs in some places. (#172404, diff --git a/ChangeLog.pre-2-10 b/ChangeLog.pre-2-10 index ee22fdd..7bc0276 100644 --- a/ChangeLog.pre-2-10 +++ b/ChangeLog.pre-2-10 @@ -1,3 +1,8 @@ +2005-04-05 Matthias Clasen + + * glib/gfileutils.c (get_contents_stdio): Avoid memory + leaks in borderline cases. (#172612, Morten Welinder) + 2005-04-04 Matthias Clasen * glib/gconvert.c: Clarify docs in some places. (#172404, diff --git a/ChangeLog.pre-2-12 b/ChangeLog.pre-2-12 index ee22fdd..7bc0276 100644 --- a/ChangeLog.pre-2-12 +++ b/ChangeLog.pre-2-12 @@ -1,3 +1,8 @@ +2005-04-05 Matthias Clasen + + * glib/gfileutils.c (get_contents_stdio): Avoid memory + leaks in borderline cases. (#172612, Morten Welinder) + 2005-04-04 Matthias Clasen * glib/gconvert.c: Clarify docs in some places. (#172404, diff --git a/ChangeLog.pre-2-8 b/ChangeLog.pre-2-8 index ee22fdd..7bc0276 100644 --- a/ChangeLog.pre-2-8 +++ b/ChangeLog.pre-2-8 @@ -1,3 +1,8 @@ +2005-04-05 Matthias Clasen + + * glib/gfileutils.c (get_contents_stdio): Avoid memory + leaks in borderline cases. (#172612, Morten Welinder) + 2005-04-04 Matthias Clasen * glib/gconvert.c: Clarify docs in some places. (#172404, diff --git a/glib/gfileutils.c b/glib/gfileutils.c index 3665215..d2263ea 100644 --- a/glib/gfileutils.c +++ b/glib/gfileutils.c @@ -473,6 +473,7 @@ get_contents_stdio (const gchar *display_filename, gchar *str = NULL; size_t total_bytes = 0; size_t total_allocated = 0; + gchar *tmp; g_assert (f != NULL); @@ -490,9 +491,9 @@ get_contents_stdio (const gchar *display_filename, else total_allocated = MIN (bytes + 1, sizeof (buf)); - str = g_try_realloc (str, total_allocated); + tmp = g_try_realloc (str, total_allocated); - if (str == NULL) + if (tmp == NULL) { g_set_error (error, G_FILE_ERROR, @@ -503,6 +504,8 @@ get_contents_stdio (const gchar *display_filename, goto error; } + + str = tmp; } if (ferror (f)) @@ -523,7 +526,7 @@ get_contents_stdio (const gchar *display_filename, fclose (f); - if (total_bytes == 0) + if (total_allocated == 0) str = g_new (gchar, 1); str[total_bytes] = '\0';