Fix memory leak in sensors_get_label(). Reported by John Naylon.

git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@3031 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
Jean Delvare committed 2005-07-15 08:57:43 +00:00
1 parent 8e3aebf21d
commit f98d12b4b5
2 files changed
+7 -17

No files matched your search

+1
View File
@@ -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)
+6 -17
View File
@@ -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;