Show
Ignore:
Timestamp:
07/15/05 10:57:43 (8 years ago)
Author:
khali
Message:

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

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/lib/access.c

    r2692 r3031  
    140140/* Look up the label which belongs to this chip. Note that chip should not 
    141141   contain wildcard values! *result is newly allocated (free it yourself). 
    142    This function will return 0 on success, and <0 on failure.   
    143    Changed behaviour as of libsensors.so.1: now we actually take notice 
    144    of the logical class, as documented, but not done before! */ 
     142   This function will return 0 on success, and <0 on failure. 
     143   If no label exists for this feature, its name is returned itself. */   
    145144int sensors_get_label(sensors_chip_name name, int feature, char **result) 
    146145{ 
    147146  const sensors_chip *chip; 
    148147  const sensors_chip_feature *featureptr; 
    149   const sensors_chip_feature *alt_featureptr; 
    150148  int i; 
    151149 
     
    155153  if (! (featureptr = sensors_lookup_feature_nr(name.prefix,feature))) 
    156154    return -SENSORS_ERR_NO_ENTRY; 
    157   if (featureptr->logical_mapping == SENSORS_NO_MAPPING) 
    158     alt_featureptr = NULL; 
    159   else if (! (alt_featureptr = 
    160                    sensors_lookup_feature_nr(name.prefix, 
    161                                              featureptr->logical_mapping))) 
    162     return -SENSORS_ERR_NO_ENTRY; 
     155 
    163156  for (chip = NULL; (chip = sensors_for_all_config_chips(name,chip));) 
    164157    for (i = 0; i < chip->labels_count; i++) 
     
    168161        if (! (*result = strdup(chip->labels[i].value))) 
    169162          sensors_fatal_error("sensors_get_label","Allocating label text"); 
    170         return 0; /* Exact match always overrules! */ 
    171       } else if (alt_featureptr &&  
    172                  !strcasecmp(alt_featureptr->name, chip->labels[i].name)) { 
    173         if (*result) 
    174           free(*result); 
    175         if (! (*result = strdup(chip->labels[i].value))) 
    176           sensors_fatal_error("sensors_get_label","Allocating label text"); 
     163        return 0; 
    177164      } 
     165 
     166  /* No label, return the feature name instead */ 
    178167  if (! (*result = strdup(featureptr->name))) 
    179168    sensors_fatal_error("sensors_get_label","Allocating label text");