Michael McConville wrote:
> 1. realloc acts like malloc when ptr == NULL
> 2. no need to check for NULL before free
> 
> ok?

I found the same pair in libc. ok?


Index: lib/libc/time/strftime.c
===================================================================
RCS file: /cvs/src/lib/libc/time/strftime.c,v
retrieving revision 1.28
diff -u -p -r1.28 strftime.c
--- lib/libc/time/strftime.c    24 Oct 2015 18:13:18 -0000      1.28
+++ lib/libc/time/strftime.c    24 Dec 2015 17:53:52 -0000
@@ -670,10 +670,9 @@ _loc(void)
                goto bad_locale;
        bufsize = namesize + st.st_size;
        locale_buf = NULL;
-       nlbuf = (lbuf == NULL) ? malloc(bufsize) : realloc(lbuf, bufsize);
+       nlbuf = realloc(lbuf, bufsize);
        if (nlbuf == NULL) {
-               if (lbuf)
-                       free(lbuf);
+               free(lbuf);
                lbuf = NULL;
                goto bad_locale;
        }

Reply via email to