diff --git a/CHANGES b/CHANGES index b7f23bfc..fe104583 100644 --- a/CHANGES +++ b/CHANGES @@ -20,6 +20,7 @@ ask CVS about it: 2.9.2 (2005????) File doc/chips/*: Big update (2.6 backport) Library: Drop ds1780-specific code (now use adm9240) + Fix memory leak in sensors_get_label() Man page isaset.8: Fix typos Module adm1031: Fix broken kfree() calls Module i2c-ali1563: New (2.6 backport by Winbond) diff --git a/lib/access.c b/lib/access.c index 002f0692..11f918ed 100644 --- a/lib/access.c +++ b/lib/access.c @@ -139,14 +139,12 @@ int sensors_chip_name_has_wildcards(sensors_chip_name chip) /* Look up the label which belongs to this chip. Note that chip should not contain wildcard values! *result is newly allocated (free it yourself). - This function will return 0 on success, and <0 on failure. - Changed behaviour as of libsensors.so.1: now we actually take notice - of the logical class, as documented, but not done before! */ + This function will return 0 on success, and <0 on failure. + If no label exists for this feature, its name is returned itself. */ int sensors_get_label(sensors_chip_name name, int feature, char **result) { const sensors_chip *chip; const sensors_chip_feature *featureptr; - const sensors_chip_feature *alt_featureptr; int i; *result=NULL; @@ -154,12 +152,7 @@ int sensors_get_label(sensors_chip_name name, int feature, char **result) return -SENSORS_ERR_WILDCARDS; if (! (featureptr = sensors_lookup_feature_nr(name.prefix,feature))) return -SENSORS_ERR_NO_ENTRY; - if (featureptr->logical_mapping == SENSORS_NO_MAPPING) - alt_featureptr = NULL; - else if (! (alt_featureptr = - sensors_lookup_feature_nr(name.prefix, - featureptr->logical_mapping))) - return -SENSORS_ERR_NO_ENTRY; + for (chip = NULL; (chip = sensors_for_all_config_chips(name,chip));) for (i = 0; i < chip->labels_count; i++) if (!strcasecmp(featureptr->name, chip->labels[i].name)) { @@ -167,14 +160,10 @@ int sensors_get_label(sensors_chip_name name, int feature, char **result) free(*result); if (! (*result = strdup(chip->labels[i].value))) sensors_fatal_error("sensors_get_label","Allocating label text"); - return 0; /* Exact match always overrules! */ - } else if (alt_featureptr && - !strcasecmp(alt_featureptr->name, chip->labels[i].name)) { - if (*result) - free(*result); - if (! (*result = strdup(chip->labels[i].value))) - sensors_fatal_error("sensors_get_label","Allocating label text"); + return 0; } + + /* No label, return the feature name instead */ if (! (*result = strdup(featureptr->name))) sensors_fatal_error("sensors_get_label","Allocating label text"); return 0;