diff options
author | khali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0> | 2009-06-20 10:04:52 +0000 |
---|---|---|
committer | khali <khali@7894878c-1315-0410-8ee3-d5d059ff63e0> | 2009-06-20 10:04:52 +0000 |
commit | 77e7caff0a275246feb6dfad12d71b63a81aa2d9 (patch) | |
tree | cad657a5d96987e761b1d0f42123d1b3a761e336 /lib | |
parent | e3649b3677e1c3474b7c5d6fa558d0bef587b6aa (diff) | |
download | lm-sensors-77e7caff0a275246feb6dfad12d71b63a81aa2d9.tar.gz |
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.
git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@5740 7894878c-1315-0410-8ee3-d5d059ff63e0
Diffstat (limited to 'lib')
-rw-r--r-- | lib/data.c | 5 | ||||
-rw-r--r-- | lib/libsensors.3 | 10 | ||||
-rw-r--r-- | lib/sensors.h | 5 |
3 files changed, 18 insertions, 2 deletions
@@ -54,6 +54,11 @@ sensors_bus *sensors_proc_bus = NULL; int sensors_proc_bus_count = 0; int sensors_proc_bus_max = 0; +void sensors_free_chip_name(sensors_chip_name *chip) +{ + free(chip->prefix); +} + /* Parse a chip name to the internal representation. These are valid names: diff --git a/lib/libsensors.3 b/lib/libsensors.3 index 2fa9ce5e..8fc80710 100644 --- a/lib/libsensors.3 +++ b/lib/libsensors.3 @@ -42,6 +42,7 @@ libsensors \- publicly accessible functions provided by the sensors library /* Chip name handling */ .BI "int sensors_parse_chip_name(const char *" orig_name "," .BI " sensors_chip_name *" res ");" +.BI "void sensors_free_chip_name(sensors_chip_name *" chip ");" .BI "int sensors_snprintf_chip_name(char *" str ", size_t " size "," .BI " const sensors_chip_name *" chip ");" .BI "const char *sensors_get_adapter_name(const sensors_bus_id *" bus ");" @@ -101,7 +102,14 @@ is a string representing the version of libsensors. .B sensors_parse_chip_name() parses a chip name to the internal representation. Return 0 on success, -<0 on error. +<0 on error. Make sure to call sensors_free_chip_name() when you're done +with the data. + +.B sensors_free_chip_name() +frees the memory that may have been allocated for the internal +representation of a chip name. You only have to call this for chip +names which do not originate from libsensors itself (that is, chip +names which were generated by sensors_parse_chip_name()). .B sensors_snprintf_chip_name() prints a chip name from its internal representation. Note that chip should diff --git a/lib/sensors.h b/lib/sensors.h index ab461378..8471006f 100644 --- a/lib/sensors.h +++ b/lib/sensors.h @@ -31,7 +31,7 @@ when the API + ABI breaks), the third digit is incremented to track small API additions like new flags / enum values. The second digit is for tracking larger additions like new methods. */ -#define SENSORS_API_VERSION 0x410 +#define SENSORS_API_VERSION 0x420 #define SENSORS_CHIP_NAME_PREFIX_ANY NULL #define SENSORS_CHIP_NAME_ADDR_ANY (-1) @@ -80,6 +80,9 @@ void sensors_cleanup(void); on error. */ int sensors_parse_chip_name(const char *orig_name, sensors_chip_name *res); +/* Free memory allocated for the internal representation of a chip name. */ +void sensors_free_chip_name(sensors_chip_name *chip); + /* Print a chip name from its internal representation. Note that chip should not contain wildcard values! Return the number of characters printed on success (same as snprintf), <0 on error. */ |