kvm_malloc:

When malloc fails. don't try to memset NULL pointer, it cause core dump
Replace malloc+memset with calloc, theoretically it can do some
optimization of zeroing process internally
Improve error diagnostic
This commit is contained in:
ache 1996-11-11 08:28:47 +00:00
parent 3f0c80b2e9
commit 26976c4aee

View File

@ -155,9 +155,9 @@ _kvm_malloc(kd, n)
{
void *p;
if ((p = malloc(n)) == NULL)
_kvm_err(kd, kd->program, strerror(errno));
memset(p, 0, n);
if ((p = calloc(n, sizeof(char))) == NULL)
_kvm_err(kd, kd->program, "can't allocate %u bytes: %s",
n, strerror(errno));
return (p);
}