provide xrealloc, and don't cast and use malloc and realloc directly.
This commit is contained in:
parent
2cce1500a2
commit
596c6ec5db
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: paths.c,v 1.35 2007/09/20 14:14:25 christos Exp $ */
|
||||
/* $NetBSD: paths.c,v 1.36 2007/09/27 17:52:16 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 Matt Thomas <matt@3am-software.com>
|
||||
|
@ -30,7 +30,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: paths.c,v 1.35 2007/09/20 14:14:25 christos Exp $");
|
||||
__RCSID("$NetBSD: paths.c,v 1.36 2007/09/27 17:52:16 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include <err.h>
|
||||
|
@ -407,7 +407,7 @@ _rtld_sysctl(const char *name, void *oldp, size_t *oldlen)
|
|||
|
||||
/* Start with 16 entries, will grow it up as needed. */
|
||||
res_size = 16 * sizeof(struct sysctlnode);
|
||||
result = (struct sysctlnode *)malloc(res_size);
|
||||
result = xmalloc(res_size);
|
||||
if (result == NULL)
|
||||
return (-1);
|
||||
|
||||
|
@ -424,17 +424,17 @@ _rtld_sysctl(const char *name, void *oldp, size_t *oldlen)
|
|||
query.sysctl_flags = SYSCTL_VERSION;
|
||||
|
||||
n = res_size;
|
||||
if (sysctl(mib, miblen+1, result, &n, &query,
|
||||
if (sysctl(mib, miblen + 1, result, &n, &query,
|
||||
sizeof(query)) == -1) {
|
||||
if (errno != ENOMEM)
|
||||
goto bad;
|
||||
/* Grow up result */
|
||||
res_size = n;
|
||||
newresult = (struct sysctlnode *)realloc(result, res_size);
|
||||
newresult = xrealloc(result, res_size);
|
||||
if (newresult == NULL)
|
||||
goto bad;
|
||||
result = newresult;
|
||||
if (sysctl(mib, miblen+1, result, &n, &query,
|
||||
if (sysctl(mib, miblen + 1, result, &n, &query,
|
||||
sizeof(query)) == -1)
|
||||
goto bad;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: rtldenv.h,v 1.7 2006/05/22 19:49:09 drochner Exp $ */
|
||||
/* $NetBSD: rtldenv.h,v 1.8 2007/09/27 17:52:16 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 Matt Thomas <matt@3am-software.com>
|
||||
|
@ -35,6 +35,7 @@
|
|||
|
||||
void *xcalloc(size_t);
|
||||
void *xmalloc(size_t);
|
||||
void *xrealloc(void *, size_t);
|
||||
char *xstrdup(const char *);
|
||||
|
||||
#ifdef RTLD_LOADER
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: xmalloc.c,v 1.5 2004/10/22 05:39:57 skrll Exp $ */
|
||||
/* $NetBSD: xmalloc.c,v 1.6 2007/09/27 17:52:16 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1996 John D. Polstra.
|
||||
|
@ -33,7 +33,7 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: xmalloc.c,v 1.5 2004/10/22 05:39:57 skrll Exp $");
|
||||
__RCSID("$NetBSD: xmalloc.c,v 1.6 2007/09/27 17:52:16 christos Exp $");
|
||||
#endif /* not lint */
|
||||
|
||||
#include "rtldenv.h"
|
||||
|
@ -59,6 +59,16 @@ xmalloc(size_t size)
|
|||
return p;
|
||||
}
|
||||
|
||||
void *
|
||||
xrealloc(void *p, size_t size)
|
||||
{
|
||||
p = realloc(p, size);
|
||||
|
||||
if (p == NULL)
|
||||
xerr(1, "%s", xstrerror(errno));
|
||||
return p;
|
||||
}
|
||||
|
||||
char*
|
||||
xstrdup(const char *s)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue