diff options
-rw-r--r-- | src/fan/fan.c | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/src/fan/fan.c b/src/fan/fan.c index 1423952..adc49cc 100644 --- a/src/fan/fan.c +++ b/src/fan/fan.c @@ -96,11 +96,12 @@ static cim_fan_error_t libsensors2cim_fan_error(int err) { } static const char * sprintf_chip_name(sensors_chip_name const *name) { - /** @return NULL on error, cstring otherwise */ - static char buf[MAX_CHIP_NAME_LENGTH]; - if (sensors_snprintf_chip_name(buf, MAX_CHIP_NAME_LENGTH, name) < 0) + /** @return NULL on error, cstring otherwise, it needs to be freed */ + int charcnt; + char buf[MAX_CHIP_NAME_LENGTH]; + if ((charcnt = sensors_snprintf_chip_name(buf, MAX_CHIP_NAME_LENGTH, name)) < 0) return NULL; - return buf; + return strndup(buf, charcnt); } static cim_fan_error_t reload_config_file(char const * fp) { @@ -223,7 +224,6 @@ static struct cim_fan * _load_fan_data( sensors_chip_name const *chip , sensors_feature const *feature) { struct cim_fan *f; - char const *chip_name; char * tmp; int length; int const sfs[] = { @@ -250,14 +250,10 @@ static struct cim_fan * _load_fan_data( sensors_chip_name const *chip if (!(f = calloc(1, sizeof(struct cim_fan)))) { return NULL; } - if (!(chip_name = sprintf_chip_name(chip))) { + if (!(f->chip_name = sprintf_chip_name(chip))) { error("could not get chip name\n"); goto lab_err_free_fan; } - if (!(f->chip_name = strdup(chip_name))) { - perror("strdup"); - goto lab_err_free_fan; - } f->sys_path = chip->path; if (!(f->name = sensors_get_label(chip, feature))) { error("could not get fan name for chip: %s\n", |