Changeset 5740

Show
Ignore:
Timestamp:
06/20/09 12:04:52 (4 years ago)
Author:
khali
Message:

libsensors: New method to free the memory allocated for the internal
representation of chip names.
sensord, sensors: Fix a memory leak when one or more chip names are
provided on the command line.

Location:
lm-sensors/trunk
Files:
9 modified

Legend:

Unmodified
Added
Removed
  • lm-sensors/trunk/CHANGES

    r5737 r5740  
    66  isaset: Use geteuid instead of getuid so that setuid bit works 
    77  libsensors: Don't rely on dirent->dt_type being set 
     8              New method to free the memory allocated for chip names 
    89  Makefile: Include generated source files in dependency checking 
    910            Make it possible to skip building of the static library 
     
    1718           Disable unit scaling for fan speeds 
    1819           Use daemon logging facility instead of local4 by default 
     20           Fix a memory leak when a chip name is provided 
     21  sensors: Fix a memory leak when a chip name is provided 
    1922  sensors-detect: Add nNidia nForce MCP78S SMBus detection 
    2023                  Display Super-I/O address even if LD is disabled 
  • lm-sensors/trunk/doc/libsensors-API.txt

    r5663 r5740  
    66authors can quickly figure out how to test for the availability of a 
    77given new feature. 
     8 
     90x420   lm-sensors 3.1.1 
     10* Added a method to free the memory allocated by sensors_parse_chip_name() 
     11  void sensors_free_chip_name(sensors_chip_name *chip); 
    812 
    9130x410   lm-sensors 3.1.0 
  • lm-sensors/trunk/lib/data.c

    r5674 r5740  
    5454int sensors_proc_bus_count = 0; 
    5555int sensors_proc_bus_max = 0; 
     56 
     57void sensors_free_chip_name(sensors_chip_name *chip) 
     58{ 
     59        free(chip->prefix); 
     60} 
    5661 
    5762/* 
  • lm-sensors/trunk/lib/libsensors.3

    r5654 r5740  
    4343.BI "int sensors_parse_chip_name(const char *" orig_name "," 
    4444.BI "                            sensors_chip_name *" res ");" 
     45.BI "void sensors_free_chip_name(sensors_chip_name *" chip ");" 
    4546.BI "int sensors_snprintf_chip_name(char *" str ", size_t " size "," 
    4647.BI "                               const sensors_chip_name *" chip ");" 
     
    102103.B sensors_parse_chip_name() 
    103104parses a chip name to the internal representation. Return 0 on success, 
    104 <0 on error. 
     105<0 on error. Make sure to call sensors_free_chip_name() when you're done 
     106with the data. 
     107 
     108.B sensors_free_chip_name() 
     109frees the memory that may have been allocated for the internal 
     110representation of a chip name. You only have to call this for chip 
     111names which do not originate from libsensors itself (that is, chip 
     112names which were generated by sensors_parse_chip_name()). 
    105113 
    106114.B sensors_snprintf_chip_name() 
  • lm-sensors/trunk/lib/sensors.h

    r5663 r5740  
    3232   API additions like new flags / enum values. The second digit is for tracking 
    3333   larger additions like new methods. */ 
    34 #define SENSORS_API_VERSION             0x410 
     34#define SENSORS_API_VERSION             0x420 
    3535 
    3636#define SENSORS_CHIP_NAME_PREFIX_ANY    NULL 
     
    8080   on error. */ 
    8181int sensors_parse_chip_name(const char *orig_name, sensors_chip_name *res); 
     82 
     83/* Free memory allocated for the internal representation of a chip name. */ 
     84void sensors_free_chip_name(sensors_chip_name *chip); 
    8285 
    8386/* Print a chip name from its internal representation. Note that chip should 
  • lm-sensors/trunk/prog/sensord/args.c

    r5737 r5740  
    256256                        fprintf(stderr, "Invalid chip name `%s': %s\n", arg, 
    257257                                sensors_strerror(err)); 
     258                        for (i--; i >= 0; i--) 
     259                                sensors_free_chip_name(sensord_args.chipNames + i); 
    258260                        return -1; 
    259261                } 
     
    263265        return 0; 
    264266} 
     267 
     268void freeChips() 
     269{ 
     270        int i; 
     271 
     272        for (i = 0; i < sensord_args.numChipNames; i++) 
     273                sensors_free_chip_name(sensord_args.chipNames + i); 
     274} 
  • lm-sensors/trunk/prog/sensord/sensord.c

    r5734 r5740  
    234234                exit(EXIT_FAILURE); 
    235235 
    236         if (loadLib(sensord_args.cfgFile)) 
    237                 exit(EXIT_FAILURE); 
     236        if (loadLib(sensord_args.cfgFile)) { 
     237                freeChips(); 
     238                exit(EXIT_FAILURE); 
     239        } 
    238240 
    239241        if (!sensord_args.doCGI) 
     
    242244        if (sensord_args.rrdFile) { 
    243245                ret = rrdInit(); 
    244                 if (ret) 
     246                if (ret) { 
     247                        freeChips(); 
    245248                        exit(EXIT_FAILURE); 
     249                } 
    246250        } 
    247251 
     
    254258        } 
    255259 
     260        freeChips(); 
    256261        if (unloadLib()) 
    257262                exit(EXIT_FAILURE); 
  • lm-sensors/trunk/prog/sensord/sensord.h

    r5736 r5740  
    3232extern int parseArgs(int argc, char **argv); 
    3333extern int parseChips(int argc, char **argv); 
     34extern void freeChips(void); 
    3435 
    3536/* from lib.c */ 
  • lm-sensors/trunk/prog/sensors/main.c

    r5632 r5740  
    335335                        } 
    336336                        cnt += do_the_real_work(&chip, &err); 
     337                        sensors_free_chip_name(&chip); 
    337338                } 
    338339