use ecalloc
This commit is contained in:
parent
142f2b406b
commit
093dea8259
@ -1,12 +1,12 @@
|
||||
# $NetBSD: Makefile,v 1.5 2011/05/26 12:56:33 joerg Exp $
|
||||
# $NetBSD: Makefile,v 1.6 2015/12/14 03:15:10 christos Exp $
|
||||
|
||||
USE_FORT?= yes # setgid
|
||||
PROG= pmap
|
||||
SRCS= main.c pmap.c
|
||||
BINGRP= kmem
|
||||
BINMODE= 2555
|
||||
LDADD= -lkvm
|
||||
DPADD= ${LIBKVM}
|
||||
LDADD= -lutil -lkvm
|
||||
DPADD= ${LIBUTIL} ${LIBKVM}
|
||||
|
||||
CWARNFLAGS.clang+= -Wno-format-extra-args
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: main.c,v 1.25 2015/12/13 18:09:00 christos Exp $ */
|
||||
/* $NetBSD: main.c,v 1.26 2015/12/14 03:15:10 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
||||
@ -31,7 +31,7 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: main.c,v 1.25 2015/12/13 18:09:00 christos Exp $");
|
||||
__RCSID("$NetBSD: main.c,v 1.26 2015/12/14 03:15:10 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <sys/param.h>
|
||||
@ -48,6 +48,7 @@ __RCSID("$NetBSD: main.c,v 1.25 2015/12/13 18:09:00 christos Exp $");
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <signal.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "pmap.h"
|
||||
#include "main.h"
|
||||
@ -475,7 +476,7 @@ load_name_cache(kvm_t *kd)
|
||||
|
||||
_KDEREF(kd, nchash_addr, &lnchash, sizeof(lnchash));
|
||||
nchash = (size_t)lnchash + 1;
|
||||
nchashtbl = malloc(nchash * sizeof(*nchashtbl));
|
||||
nchashtbl = ecalloc(nchash, sizeof(*nchashtbl));
|
||||
_KDEREF(kd, nchashtbl_addr, nchashtbl, sizeof(*nchashtbl) * nchash);
|
||||
|
||||
ncpp = &_ncpp;
|
||||
@ -512,7 +513,7 @@ cache_enter(u_long i, struct namecache *ncp)
|
||||
i, ncp->nc_vp, ncp->nc_dvp,
|
||||
ncp->nc_nlen, ncp->nc_nlen, ncp->nc_name);
|
||||
|
||||
ce = malloc(sizeof(struct cache_entry));
|
||||
ce = emalloc(sizeof(struct cache_entry));
|
||||
|
||||
ce->ce_vp = ncp->nc_vp;
|
||||
ce->ce_pvp = ncp->nc_dvp;
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: pmap.c,v 1.51 2012/10/29 16:25:25 para Exp $ */
|
||||
/* $NetBSD: pmap.c,v 1.52 2015/12/14 03:15:10 christos Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2002, 2003 The NetBSD Foundation, Inc.
|
||||
@ -31,10 +31,11 @@
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
#ifndef lint
|
||||
__RCSID("$NetBSD: pmap.c,v 1.51 2012/10/29 16:25:25 para Exp $");
|
||||
__RCSID("$NetBSD: pmap.c,v 1.52 2015/12/14 03:15:10 christos Exp $");
|
||||
#endif
|
||||
|
||||
#include <string.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "pmap.h"
|
||||
#include "main.h"
|
||||
@ -565,22 +566,23 @@ dump_amap(kvm_t *kd, struct kbit *amap)
|
||||
* Assume that sizeof(struct vm_anon *) >= sizeof(size_t) and
|
||||
* allocate that amount of space.
|
||||
*/
|
||||
l = sizeof(struct vm_anon *) * D(amap, amap)->am_maxslot;
|
||||
am_anon = malloc(l);
|
||||
am_anon = ecalloc(D(amap, amap)->am_maxslot, sizeof(*am_anon));
|
||||
l = D(amap, amap)->am_maxslot * sizeof(*am_anon);
|
||||
_KDEREF(kd, (u_long)D(amap, amap)->am_anon, am_anon, l);
|
||||
|
||||
l = sizeof(int) * D(amap, amap)->am_maxslot;
|
||||
am_bckptr = malloc(l);
|
||||
l = D(amap, amap)->am_maxslot * sizeof(*am_bckptr);
|
||||
am_bckptr = ecalloc(D(amap, amap)->am_maxslot, sizeof(*am_bckptr));
|
||||
_KDEREF(kd, (u_long)D(amap, amap)->am_bckptr, am_bckptr, l);
|
||||
|
||||
l = sizeof(int) * D(amap, amap)->am_maxslot;
|
||||
am_slots = malloc(l);
|
||||
l = D(amap, amap)->am_maxslot * sizeof(*am_slots);
|
||||
am_slots = ecalloc(D(amap, amap)->am_maxslot, sizeof(*am_slots));
|
||||
_KDEREF(kd, (u_long)D(amap, amap)->am_slots, am_slots, l);
|
||||
|
||||
if (D(amap, amap)->am_ppref != NULL &&
|
||||
D(amap, amap)->am_ppref != PPREF_NONE) {
|
||||
l = sizeof(int) * D(amap, amap)->am_maxslot;
|
||||
am_ppref = malloc(l);
|
||||
am_ppref = ecalloc(
|
||||
D(amap, amap)->am_maxslot, sizeof(*am_ppref));
|
||||
l = D(amap, amap)->am_maxslot * sizeof(*am_ppref);
|
||||
_KDEREF(kd, (u_long)D(amap, amap)->am_ppref, am_ppref, l);
|
||||
} else {
|
||||
am_ppref = NULL;
|
||||
|
Loading…
Reference in New Issue
Block a user