From: Jens Axboe Date: Tue, 30 Sep 2014 16:08:08 +0000 (-0600) Subject: Use calloc() instead of malloc + memset X-Git-Tag: fio-2.1.13~9 X-Git-Url: https://git.kernel.dk/?p=fio.git;a=commitdiff_plain;h=e75cc8f3a296fe5910eee9b7f25cc8cb524b4518 Use calloc() instead of malloc + memset Signed-off-by: Jens Axboe --- diff --git a/iolog.c b/iolog.c index ef8b8414..cfcab271 100644 --- a/iolog.c +++ b/iolog.c @@ -539,9 +539,9 @@ int init_iolog(struct thread_data *td) void setup_log(struct io_log **log, struct log_params *p, const char *filename) { - struct io_log *l = malloc(sizeof(*l)); + struct io_log *l; - memset(l, 0, sizeof(*l)); + l = calloc(1, sizeof(*l)); l->nr_samples = 0; l->max_samples = 1024; l->log_type = p->log_type; diff --git a/json.c b/json.c index 7480a61f..6145ee48 100644 --- a/json.c +++ b/json.c @@ -8,18 +8,12 @@ struct json_object *json_create_object(void) { - struct json_object *obj = malloc(sizeof(struct json_object)); - if (obj) - memset(obj, 0, sizeof(struct json_object)); - return obj; + return calloc(1, sizeof(struct json_object)); } struct json_array *json_create_array(void) { - struct json_array *array = malloc(sizeof(struct json_array)); - if (array) - memset(array, 0, sizeof(struct json_array)); - return array; + return calloc(1, sizeof(struct json_array)); } static struct json_pair *json_create_pair(const char *name, struct json_value *value)