aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/lib/libdtrace
diff options
context:
space:
mode:
authorPedro F. Giffuni <pfg@FreeBSD.org>2016-03-14 00:34:12 +0000
committerPedro F. Giffuni <pfg@FreeBSD.org>2016-03-14 00:34:12 +0000
commit273df42911c8518ba1b3834c03c575ad4365e11f (patch)
tree338e7d25d3034f9cdc8f859a1e6c1645fac79777 /cddl/contrib/opensolaris/lib/libdtrace
parent7d980385e8d1131e2f783eb10b02ff3ebaf0454d (diff)
downloadsrc-273df42911c8518ba1b3834c03c575ad4365e11f.tar.gz
src-273df42911c8518ba1b3834c03c575ad4365e11f.zip
libdtrace: use calloc(3) instead of malloc(3) when it makes sense.
calloc(3) is faster and occasionally safer than malloc(3) + bzero(3). In one case, pointed out by Mark[1], this also cleans up a calculation. Reviewed by: markj [1] MFC after: 1 week
Notes
Notes: svn path=/head/; revision=296816
Diffstat (limited to 'cddl/contrib/opensolaris/lib/libdtrace')
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c14
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c7
-rw-r--r--cddl/contrib/opensolaris/lib/libdtrace/common/dt_strtab.c7
3 files changed, 14 insertions, 14 deletions
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c
index 77f92237e210..5fe256503f5e 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_module.c
@@ -24,6 +24,7 @@
*/
/*
* Copyright (c) 2013, Joyent, Inc. All rights reserved.
+ * Copyright (c) 2016, Pedro Giffuni. All rights reserved.
*/
#include <sys/types.h>
@@ -721,22 +722,20 @@ dt_module_load_proc(dtrace_hdl_t *dtp, dt_module_t *dmp)
return (dt_set_errno(dtp, EDT_CANTLOAD));
}
- dmp->dm_libctfp = malloc(sizeof (ctf_file_t *) * arg.dpa_count);
+ dmp->dm_libctfp = calloc(arg.dpa_count, sizeof (ctf_file_t *));
if (dmp->dm_libctfp == NULL) {
dt_proc_unlock(dtp, p);
dt_proc_release(dtp, p);
return (dt_set_errno(dtp, EDT_NOMEM));
}
- bzero(dmp->dm_libctfp, sizeof (ctf_file_t *) * arg.dpa_count);
- dmp->dm_libctfn = malloc(sizeof (char *) * arg.dpa_count);
+ dmp->dm_libctfn = calloc(arg.dpa_count, sizeof (char *));
if (dmp->dm_libctfn == NULL) {
free(dmp->dm_libctfp);
dt_proc_unlock(dtp, p);
dt_proc_release(dtp, p);
return (dt_set_errno(dtp, EDT_NOMEM));
}
- bzero(dmp->dm_libctfn, sizeof (char *) * arg.dpa_count);
dmp->dm_nctflibs = arg.dpa_count;
@@ -817,17 +816,14 @@ dt_module_load(dtrace_hdl_t *dtp, dt_module_t *dmp)
dmp->dm_nsymbuckets = _dtrace_strbuckets;
dmp->dm_symfree = 1; /* first free element is index 1 */
- dmp->dm_symbuckets = malloc(sizeof (uint_t) * dmp->dm_nsymbuckets);
- dmp->dm_symchains = malloc(sizeof (dt_sym_t) * dmp->dm_nsymelems + 1);
+ dmp->dm_symbuckets = calloc(dmp->dm_nsymbuckets, sizeof (uint_t));
+ dmp->dm_symchains = calloc(dmp->dm_nsymelems + 1, sizeof (dt_sym_t));
if (dmp->dm_symbuckets == NULL || dmp->dm_symchains == NULL) {
dt_module_unload(dtp, dmp);
return (dt_set_errno(dtp, EDT_NOMEM));
}
- bzero(dmp->dm_symbuckets, sizeof (uint_t) * dmp->dm_nsymbuckets);
- bzero(dmp->dm_symchains, sizeof (dt_sym_t) * dmp->dm_nsymelems + 1);
-
/*
* Iterate over the symbol table data buffer and insert each symbol
* name into the name hash if the name and type are valid. Then
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c
index 0c747ed133ca..a630d300dc50 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_regset.c
@@ -27,6 +27,7 @@
/*
* Copyright (c) 2012 by Delphix. All rights reserved.
+ * Copyright (c) 2016 Pedro Giffuni. All rights reserved.
*/
#include <sys/types.h>
@@ -47,15 +48,15 @@ dt_regset_create(ulong_t nregs)
if (drp == NULL)
return (NULL);
- drp->dr_bitmap = malloc(sizeof (ulong_t) * n);
- drp->dr_size = nregs;
+ drp->dr_bitmap = calloc(n, sizeof (ulong_t));
if (drp->dr_bitmap == NULL) {
dt_regset_destroy(drp);
return (NULL);
}
- bzero(drp->dr_bitmap, sizeof (ulong_t) * n);
+ drp->dr_size = nregs;
+
return (drp);
}
diff --git a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_strtab.c b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_strtab.c
index cf6bc48341db..21669c84aefc 100644
--- a/cddl/contrib/opensolaris/lib/libdtrace/common/dt_strtab.c
+++ b/cddl/contrib/opensolaris/lib/libdtrace/common/dt_strtab.c
@@ -24,6 +24,10 @@
* Use is subject to license terms.
*/
+/*
+ * Portions Copyright 2016 Pedro Giffuni. All rights reserved.
+ */
+
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/types.h>
@@ -70,12 +74,11 @@ dt_strtab_create(size_t bufsz)
return (NULL);
bzero(sp, sizeof (dt_strtab_t));
- sp->str_hash = malloc(nbuckets * sizeof (dt_strhash_t *));
+ sp->str_hash = calloc(nbuckets, sizeof (dt_strhash_t *));
if (sp->str_hash == NULL)
goto err;
- bzero(sp->str_hash, nbuckets * sizeof (dt_strhash_t *));
sp->str_hashsz = nbuckets;
sp->str_bufs = NULL;
sp->str_ptr = NULL;