mirror of
https://git.proxmox.com/git/mirror_zfs.git
synced 2025-01-13 19:50:25 +03:00
Replace zed's use of malloc with calloc
When zed allocates memory via malloc(), it typically follows that with a memset(). However, calloc() implementations can often perform optimizations when zeroing memory: https://stackoverflow.com/questions/2688466/why-mallocmemset-is-slower-than-calloc This commit replaces zed's use of malloc() with calloc(). Signed-off-by: Chris Dunlap <cdunlap@llnl.gov> Signed-off-by: Brian Behlendorf <behlendorf1@llnl.gov> Closes #2736
This commit is contained in:
parent
bee6665b88
commit
8cb8cf91df
@ -51,12 +51,10 @@ zed_conf_create(void)
|
|||||||
{
|
{
|
||||||
struct zed_conf *zcp;
|
struct zed_conf *zcp;
|
||||||
|
|
||||||
zcp = malloc(sizeof (*zcp));
|
zcp = calloc(1, sizeof (*zcp));
|
||||||
if (!zcp)
|
if (!zcp)
|
||||||
goto nomem;
|
goto nomem;
|
||||||
|
|
||||||
memset(zcp, 0, sizeof (*zcp));
|
|
||||||
|
|
||||||
zcp->syslog_facility = LOG_DAEMON;
|
zcp->syslog_facility = LOG_DAEMON;
|
||||||
zcp->min_events = ZED_MIN_EVENTS;
|
zcp->min_events = ZED_MIN_EVENTS;
|
||||||
zcp->max_events = ZED_MAX_EVENTS;
|
zcp->max_events = ZED_MAX_EVENTS;
|
||||||
|
@ -61,7 +61,7 @@ _zed_exec_create_env(zed_strings_t *zsp)
|
|||||||
for (q = zed_strings_first(zsp); q; q = zed_strings_next(zsp))
|
for (q = zed_strings_first(zsp); q; q = zed_strings_next(zsp))
|
||||||
buflen += strlen(q) + 1;
|
buflen += strlen(q) + 1;
|
||||||
|
|
||||||
buf = malloc(buflen);
|
buf = calloc(1, buflen);
|
||||||
if (!buf)
|
if (!buf)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
|
@ -82,11 +82,10 @@ zed_strings_create(void)
|
|||||||
{
|
{
|
||||||
zed_strings_t *zsp;
|
zed_strings_t *zsp;
|
||||||
|
|
||||||
zsp = malloc(sizeof (*zsp));
|
zsp = calloc(1, sizeof (*zsp));
|
||||||
if (!zsp)
|
if (!zsp)
|
||||||
return (NULL);
|
return (NULL);
|
||||||
|
|
||||||
memset(zsp, 0, sizeof (*zsp));
|
|
||||||
avl_create(&zsp->tree, _zed_strings_node_compare,
|
avl_create(&zsp->tree, _zed_strings_node_compare,
|
||||||
sizeof (zed_strings_node_t), offsetof(zed_strings_node_t, node));
|
sizeof (zed_strings_node_t), offsetof(zed_strings_node_t, node));
|
||||||
|
|
||||||
@ -131,11 +130,10 @@ zed_strings_add(zed_strings_t *zsp, const char *s)
|
|||||||
return (-1);
|
return (-1);
|
||||||
}
|
}
|
||||||
len = sizeof (zed_strings_node_t) + strlen(s) + 1;
|
len = sizeof (zed_strings_node_t) + strlen(s) + 1;
|
||||||
np = malloc(len);
|
np = calloc(1, len);
|
||||||
if (!np)
|
if (!np)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
memset(np, 0, len);
|
|
||||||
assert((char *) np->string + strlen(s) < (char *) np + len);
|
assert((char *) np->string + strlen(s) < (char *) np + len);
|
||||||
(void) strcpy(np->string, s);
|
(void) strcpy(np->string, s);
|
||||||
avl_add(&zsp->tree, np);
|
avl_add(&zsp->tree, np);
|
||||||
|
Loading…
Reference in New Issue
Block a user