i2c: initialize handle in i2c_new()

This commit is contained in:
Vanya A. Sergeev
2019-10-07 20:57:44 -05:00
parent ecdf5bddef
commit f7ba212570
+7 -1
View File
@@ -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) {