summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorderaadt <>1996-01-29 02:00:21 +0000
committerderaadt <>1996-01-29 02:00:21 +0000
commitdca8a332c7ca5c2bd156219561dc328e8caf9322 (patch)
tree578f0538b99e7ac5645b1723ce5e66deb8648d69 /src
parent38b91373d0a188ae18aa6a5848d8dbc01c6c1f21 (diff)
downloadopenbsd-dca8a332c7ca5c2bd156219561dc328e8caf9322.tar.gz
openbsd-dca8a332c7ca5c2bd156219561dc328e8caf9322.tar.bz2
openbsd-dca8a332c7ca5c2bd156219561dc328e8caf9322.zip
realloc(ptr, 0) does not free; from seebs@taniemarie.solon.com;
netbsd pr#1806
Diffstat (limited to 'src')
-rw-r--r--src/lib/libc/stdlib/malloc.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/src/lib/libc/stdlib/malloc.c b/src/lib/libc/stdlib/malloc.c
index 3c57fad024..4498a9fb6c 100644
--- a/src/lib/libc/stdlib/malloc.c
+++ b/src/lib/libc/stdlib/malloc.c
@@ -1,3 +1,5 @@
1/* $NetBSD: malloc.c,v 1.6 1996/01/17 02:45:25 jtc Exp $ */
2
1/* 3/*
2 * Copyright (c) 1983 Regents of the University of California. 4 * Copyright (c) 1983 Regents of the University of California.
3 * All rights reserved. 5 * All rights reserved.
@@ -32,8 +34,11 @@
32 */ 34 */
33 35
34#if defined(LIBC_SCCS) && !defined(lint) 36#if defined(LIBC_SCCS) && !defined(lint)
35/*static char *sccsid = "from: @(#)malloc.c 5.11 (Berkeley) 2/23/91";*/ 37#if 0
36static char *rcsid = "$Id: malloc.c,v 1.1.1.1 1995/10/18 08:42:18 deraadt Exp $"; 38static char *sccsid = "from: @(#)malloc.c 5.11 (Berkeley) 2/23/91";
39#else
40static char *rcsid = "$NetBSD: malloc.c,v 1.6 1996/01/17 02:45:25 jtc Exp $";
41#endif
37#endif /* LIBC_SCCS and not lint */ 42#endif /* LIBC_SCCS and not lint */
38 43
39/* 44/*
@@ -310,6 +315,10 @@ realloc(cp, nbytes)
310 315
311 if (cp == NULL) 316 if (cp == NULL)
312 return (malloc(nbytes)); 317 return (malloc(nbytes));
318 if (nbytes == 0) {
319 free (cp);
320 return NULL;
321 }
313 op = (union overhead *)((caddr_t)cp - sizeof (union overhead)); 322 op = (union overhead *)((caddr_t)cp - sizeof (union overhead));
314 if (op->ov_magic == MAGIC) { 323 if (op->ov_magic == MAGIC) {
315 was_alloced++; 324 was_alloced++;