dutil: Adopt the zalloc()/zfree() from perf
So that we handle const pointers, also zalloc() is much simpler just calling calloc(1, size). Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
parent
d7f5824a9e
commit
6784b03fd4
15
dutil.c
15
dutil.c
|
@ -13,12 +13,15 @@
|
|||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
void *zalloc(const size_t size)
|
||||
void *zalloc(size_t size)
|
||||
{
|
||||
void *s = malloc(size);
|
||||
if (s != NULL)
|
||||
memset(s, 0, size);
|
||||
return s;
|
||||
return calloc(1, size);
|
||||
}
|
||||
|
||||
void __zfree(void **ptr)
|
||||
{
|
||||
free(*ptr);
|
||||
*ptr = NULL;
|
||||
}
|
||||
|
||||
struct str_node *str_node__new(const char *s, bool dupstr)
|
||||
|
@ -44,7 +47,7 @@ out_delete:
|
|||
static void str_node__delete(struct str_node *snode, bool dupstr)
|
||||
{
|
||||
if (dupstr)
|
||||
free((void *)snode->s);
|
||||
zfree(&snode->s);
|
||||
free(snode);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue