From f7ba2125703c92506d2fbd808505dacdcecb2ee5 Mon Sep 17 00:00:00 2001 From: "Vanya A. Sergeev" Date: Wed, 2 Oct 2019 19:28:19 -0500 Subject: [PATCH] i2c: initialize handle in i2c_new() --- src/i2c.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/i2c.c b/src/i2c.c index 89f571f..0af093c 100644 --- a/src/i2c.c +++ b/src/i2c.c @@ -51,7 +51,13 @@ static int _i2c_error(i2c_t *i2c, int code, int c_errno, const char *fmt, ...) { } i2c_t *i2c_new(void) { - return malloc(sizeof(i2c_t)); + i2c_t *i2c = calloc(1, sizeof(i2c_t)); + if (i2c == NULL) + return NULL; + + i2c->fd = -1; + + return i2c; } void i2c_free(i2c_t *i2c) {