Source-Changes-HG archive

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

[src/trunk]: src/lib/libc/gen - To detect realloc failure, need to check the ...



details:   https://anonhg.NetBSD.org/src/rev/f7d66f6d483d
branches:  trunk
changeset: 480791:f7d66f6d483d
user:      enami <enami%NetBSD.org@localhost>
date:      Thu Jan 20 03:15:04 2000 +0000

description:
- To detect realloc failure, need to check the value just returned by it.
- Free storage on realloc failure.
- Some cosmetic changes.

diffstat:

 lib/libc/gen/setmode.c |  15 +++++++++------
 1 files changed, 9 insertions(+), 6 deletions(-)

diffs (44 lines):

diff -r 204912d9ada3 -r f7d66f6d483d lib/libc/gen/setmode.c
--- a/lib/libc/gen/setmode.c    Thu Jan 20 02:53:46 2000 +0000
+++ b/lib/libc/gen/setmode.c    Thu Jan 20 03:15:04 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: setmode.c,v 1.24 2000/01/20 02:53:46 mycroft Exp $     */
+/*     $NetBSD: setmode.c,v 1.25 2000/01/20 03:15:04 enami Exp $       */
 
 /*
  * Copyright (c) 1989, 1993, 1994
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)setmode.c  8.2 (Berkeley) 3/25/94";
 #else
-__RCSID("$NetBSD: setmode.c,v 1.24 2000/01/20 02:53:46 mycroft Exp $");
+__RCSID("$NetBSD: setmode.c,v 1.25 2000/01/20 03:15:04 enami Exp $");
 #endif
 #endif /* LIBC_SCCS and not lint */
 
@@ -164,18 +164,21 @@
                }
 }
 
-#define        ADDCMD(a, b, c, d)                                              \
+#define        ADDCMD(a, b, c, d) do {                                         \
        if (set >= endset) {                                            \
-               BITCMD *newset;                         \
+               BITCMD *newset;                                         \
                setlen += SET_LEN_INCR;                                 \
                newset = realloc(saveset, sizeof(BITCMD) * setlen);     \
-               if (!saveset)                                           \
+               if (newset == NULL) {                                   \
+                       free(saveset);                                  \
                        return (NULL);                                  \
+               }                                                       \
                set = newset + (set - saveset);                         \
                saveset = newset;                                       \
                endset = newset + (setlen - 2);                         \
        }                                                               \
-       set = addcmd(set, (a), (b), (c), (d))
+       set = addcmd(set, (a), (b), (c), (d));                          \
+} while (0)
 
 #define        STANDARD_BITS   (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
 



Home | Main Index | Thread Index | Old Index