bug-hurd
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] realloc(p,0) must do free(p)


From: Ognyan Kulev
Subject: [PATCH] realloc(p,0) must do free(p)
Date: Mon, 25 Mar 2002 20:00:24 +0200
User-agent: Mozilla/5.0 (Windows; U; WinNT4.0; en-US; rv:0.9.9) Gecko/20020311

Hi,

C89, SUSv3[1] and glibc for Linux do free(p) when realloc(p,0) is called and p != 0. The patch fixes this incompatibility in `libc/hurd/hurdmalloc.c'.

Again, this patched is not tested and it must be applied after the previous patch about `malloc((1<<31)-1)'.

Regards

[1] http://www.opengroup.org/onlinepubs/007904975/functions/realloc.html
--
Ognyan Kulev <ogi@fmi.uni-sofia.bg>, "\"Programmer\""
2002-03-25  Ognyan Kulev <ogi@fmi.uni-sofia.bg>

        * hurdmalloc.c (realloc): realloc(p,0) calls free(p) and
        returns 0 when p != 0.
--- hurdmalloc.c.patched-malloc Mon Mar 25 19:16:56 2002
+++ hurdmalloc.c        Mon Mar 25 19:47:19 2002
@@ -388,6 +388,12 @@ realloc(old_base, new_size)
        if (old_base == 0)
          return malloc (new_size);
 
+       if (new_size == 0)
+         {
+           free (old_base);
+           return 0;
+         }
+
        /*
         * Find size of old block.
         */
@@ -428,7 +434,7 @@ realloc(old_base, new_size)
          memcpy (new_base, old_base,
                  (int) (old_size < new_size ? old_size : new_size));
 
-       if (new_base || new_size == 0)
+       if (new_base)
          /* Free OLD_BASE, but only if the malloc didn't fail.  */
          free (old_base);
 

reply via email to

[Prev in Thread] Current Thread [Next in Thread]