From d1dddedf7893fe70ed5d429485c8bcd0ab43f285 Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Sat, 29 Dec 2001 15:57:15 +0000 Subject: Realloc error handling memory leak fix. --- locale/lc-time.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'locale') diff --git a/locale/lc-time.c b/locale/lc-time.c index efa56b8..203a49b 100644 --- a/locale/lc-time.c +++ b/locale/lc-time.c @@ -74,12 +74,16 @@ _nl_init_era_entries (void) } else { + struct era_entry *new_eras = eras; + if (num_eras != new_num_eras) - eras = (struct era_entry *) realloc (eras, - new_num_eras - * sizeof (struct era_entry)); - if (eras == NULL) + new_eras = + (struct era_entry *) realloc (eras, + new_num_eras + * sizeof (struct era_entry)); + if (new_eras == NULL) { + free (eras); num_eras = 0; eras = NULL; } @@ -87,6 +91,7 @@ _nl_init_era_entries (void) { const char *ptr = _NL_CURRENT (LC_TIME, _NL_TIME_ERA_ENTRIES); num_eras = new_num_eras; + eras = new_eras; for (cnt = 0; cnt < num_eras; ++cnt) { -- cgit v1.1