]> git.ipfire.org Git - thirdparty/glibc.git/blobdiff - stdlib/setenv.c
stdlib: Tune down fork arc4random tests
[thirdparty/glibc.git] / stdlib / setenv.c
index 893f081af6b5a21b999a4056757fd69d1386c0d4..ba5257d3bfafd5227ac03e09f96de5acb551f685 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 1992-2021 Free Software Foundation, Inc.
+/* Copyright (C) 1992-2023 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
 
    The GNU C Library is free software; you can redistribute it and/or
@@ -150,7 +150,9 @@ __add_to_environ (const char *name, const char *value, const char *combined,
     {
       char **new_environ;
 
-      /* We allocated this space; we can extend it.  */
+      /* We allocated this space; we can extend it.  Avoid using the raw
+        reallocated pointer to avoid GCC -Wuse-after-free.  */
+      uintptr_t ip_last_environ = (uintptr_t)last_environ;
       new_environ = (char **) realloc (last_environ,
                                       (size + 2) * sizeof (char *));
       if (new_environ == NULL)
@@ -159,7 +161,7 @@ __add_to_environ (const char *name, const char *value, const char *combined,
          return -1;
        }
 
-      if (__environ != last_environ)
+      if ((uintptr_t)__environ != ip_last_environ)
        memcpy ((char *) new_environ, (char *) __environ,
                size * sizeof (char *));
 
@@ -321,7 +323,8 @@ clearenv (void)
   return 0;
 }
 #ifdef _LIBC
-libc_freeres_fn (free_mem)
+void
+__libc_setenv_freemem (void)
 {
   /* Remove all traces.  */
   clearenv ();