Browse Source

Replace malloc() + memset() with calloc()

Instead of manually clearing the memory with memset() use calloc().

Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
master
Hauke Mehrtens 7 months ago
committed by Petr Štetiar
parent
commit
52bbc99f69
4 changed files with 5 additions and 10 deletions
  1. +1
    -2
      cli.c
  2. +1
    -2
      libuci.c
  3. +2
    -4
      ucimap.c
  4. +1
    -2
      util.c

+ 1
- 2
cli.c View File

@ -100,10 +100,9 @@ uci_lookup_section_ref(struct uci_section *s)
ti = ti->next;
}
if (!ti) {
ti = malloc(sizeof(struct uci_type_list));
ti = calloc(1, sizeof(struct uci_type_list));
if (!ti)
return NULL;
memset(ti, 0, sizeof(struct uci_type_list));
ti->next = type_list;
type_list = ti;
ti->name = s->type;


+ 1
- 2
libuci.c View File

@ -48,11 +48,10 @@ struct uci_context *uci_alloc_context(void)
{
struct uci_context *ctx;
ctx = (struct uci_context *) malloc(sizeof(struct uci_context));
ctx = (struct uci_context *) calloc(1, sizeof(struct uci_context));
if (!ctx)
return NULL;
memset(ctx, 0, sizeof(struct uci_context));
uci_list_init(&ctx->root);
uci_list_init(&ctx->delta_path);
uci_list_init(&ctx->backends);


+ 2
- 4
ucimap.c View File

@ -661,11 +661,10 @@ ucimap_parse_section(struct uci_map *map, struct uci_sectionmap *sm, struct ucim
size = sizeof(struct ucimap_list) +
n_elements * sizeof(union ucimap_data);
data->list = malloc(size);
data->list = calloc(1, size);
if (!data->list)
goto error_mem;
memset(data->list, 0, size);
data->list->size = n_elements;
} else {
ucimap_count_alloc(om, &n_alloc, &n_alloc_custom);
@ -897,10 +896,9 @@ ucimap_parse(struct uci_map *map, struct uci_package *pkg)
continue;
memset(sd, 0, sizeof(struct ucimap_section_data));
} else {
sd = malloc(sm->alloc_len);
sd = calloc(1, sm->alloc_len);
if (!sd)
continue;
memset(sd, 0, sm->alloc_len);
sd = ucimap_ptr_section(sm, sd);
}


+ 1
- 2
util.c View File

@ -36,10 +36,9 @@ __private void *uci_malloc(struct uci_context *ctx, size_t size)
{
void *ptr;
ptr = malloc(size);
ptr = calloc(1, size);
if (!ptr)
UCI_THROW(ctx, UCI_ERR_MEM);
memset(ptr, 0, size);
return ptr;
}


Loading…
Cancel
Save