[39/59] Free earlier in __tzfile_read

Message ID 20250105055750.1668721-40-eggert@cs.ucla.edu (mailing list archive)
State New
Headers
Series time: sync mktime from Gnulib |

Checks

Context Check Description
redhat-pt-bot/TryBot-apply_patch success Patch applied to master at the time it was sent

Commit Message

Paul Eggert Jan. 5, 2025, 5:57 a.m. UTC
  * time/tzfile.c (__tzfile_read): Free NEW earlier, to help the
heap manager and remove the need for a goto.
---
 time/tzfile.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
  

Patch

diff --git a/time/tzfile.c b/time/tzfile.c
index 09ebc7d8ea..d600b88e89 100644
--- a/time/tzfile.c
+++ b/time/tzfile.c
@@ -202,11 +202,15 @@  __tzfile_read (const char *file)
       && __stat64_time64 (file, &st) == 0
       && tzfile_ino == st.st_ino && tzfile_dev == st.st_dev
       && tzfile_mtime == st.st_mtime)
-    goto done;  /* Nothing to do.  */
+    {
+      free (new);
+      return true;
+    }
 
   /* Note the file is opened with cancellation in the I/O functions
      disabled and if available FD_CLOEXEC set.  */
   f = fopen (file, "rce");
+  free (new);
   if (f == NULL)
     goto ret_free_transitions;
   off_t f_offset = 0;
@@ -576,14 +580,11 @@  __tzfile_read (const char *file)
   tzfile_ino = st.st_ino;
   tzfile_mtime = st.st_mtime;
 
- done:
-  free (new);
   return true;
 
  lose:
   fclose (f);
  ret_free_transitions:
-  free (new);
   free (transitions);
   transitions = NULL;
   tzfile_mtime = 0;