mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-01 08:27:59 +00:00
Reduce code duplication: use calloc() intead of malloc()
and memset afterward.
This commit is contained in:
parent
b7f8e2dab3
commit
01c56ef230
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=183986
@ -244,11 +244,10 @@ kvm_openfiles(uf, mf, sf, flag, errout)
|
||||
{
|
||||
kvm_t *kd;
|
||||
|
||||
if ((kd = malloc(sizeof(*kd))) == NULL) {
|
||||
if ((kd = calloc(1, sizeof(*kd))) == NULL) {
|
||||
(void)strlcpy(errout, strerror(errno), _POSIX2_LINE_MAX);
|
||||
return (0);
|
||||
}
|
||||
memset(kd, 0, sizeof(*kd));
|
||||
kd->program = 0;
|
||||
return (_kvm_open(kd, uf, mf, flag, errout));
|
||||
}
|
||||
@ -263,13 +262,12 @@ kvm_open(uf, mf, sf, flag, errstr)
|
||||
{
|
||||
kvm_t *kd;
|
||||
|
||||
if ((kd = malloc(sizeof(*kd))) == NULL) {
|
||||
if ((kd = calloc(1, sizeof(*kd))) == NULL) {
|
||||
if (errstr != NULL)
|
||||
(void)fprintf(stderr, "%s: %s\n",
|
||||
errstr, strerror(errno));
|
||||
return (0);
|
||||
}
|
||||
memset(kd, 0, sizeof(*kd));
|
||||
kd->program = errstr;
|
||||
return (_kvm_open(kd, uf, mf, flag, NULL));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user