summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES3
-rw-r--r--doc/libsensors-API.txt4
-rw-r--r--lib/data.c5
-rw-r--r--lib/libsensors.310
-rw-r--r--lib/sensors.h5
-rw-r--r--prog/sensord/args.c10
-rw-r--r--prog/sensord/sensord.c9
-rw-r--r--prog/sensord/sensord.h1
-rw-r--r--prog/sensors/main.c1
9 files changed, 44 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index d8af1786..4a4493e4 100644
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,7 @@ SVN-HEAD
isadump: Use geteuid instead of getuid so that setuid bit works
isaset: Use geteuid instead of getuid so that setuid bit works
libsensors: Don't rely on dirent->dt_type being set
+ New method to free the memory allocated for chip names
Makefile: Include generated source files in dependency checking
Make it possible to skip building of the static library
fancontrol: Add support for absolute path to hwmon devices
@@ -16,6 +17,8 @@ SVN-HEAD
Don't use the system log when generating a CGI script
Disable unit scaling for fan speeds
Use daemon logging facility instead of local4 by default
+ Fix a memory leak when a chip name is provided
+ sensors: Fix a memory leak when a chip name is provided
sensors-detect: Add nNidia nForce MCP78S SMBus detection
Display Super-I/O address even if LD is disabled
Differentiate between PC8374L and WPCD377I
diff --git a/doc/libsensors-API.txt b/doc/libsensors-API.txt
index 7f31aff6..b244370e 100644
--- a/doc/libsensors-API.txt
+++ b/doc/libsensors-API.txt
@@ -6,6 +6,10 @@ over time. This document summarizes these evolutions so that application
authors can quickly figure out how to test for the availability of a
given new feature.
+0x420 lm-sensors 3.1.1
+* Added a method to free the memory allocated by sensors_parse_chip_name()
+ void sensors_free_chip_name(sensors_chip_name *chip);
+
0x410 lm-sensors 3.1.0
* Added bus type "acpi":
#define SENSORS_BUS_TYPE_ACPI
diff --git a/lib/data.c b/lib/data.c
index 4f0072eb..89452c44 100644
--- a/lib/data.c
+++ b/lib/data.c
@@ -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. */
diff --git a/prog/sensord/args.c b/prog/sensord/args.c
index e109bd22..929ab0aa 100644
--- a/prog/sensord/args.c
+++ b/prog/sensord/args.c
@@ -255,6 +255,8 @@ int parseChips(int argc, char **argv)
if (err) {
fprintf(stderr, "Invalid chip name `%s': %s\n", arg,
sensors_strerror(err));
+ for (i--; i >= 0; i--)
+ sensors_free_chip_name(sensord_args.chipNames + i);
return -1;
}
}
@@ -262,3 +264,11 @@ int parseChips(int argc, char **argv)
return 0;
}
+
+void freeChips()
+{
+ int i;
+
+ for (i = 0; i < sensord_args.numChipNames; i++)
+ sensors_free_chip_name(sensord_args.chipNames + i);
+}
diff --git a/prog/sensord/sensord.c b/prog/sensord/sensord.c
index 1a7ff6c2..8b75cad8 100644
--- a/prog/sensord/sensord.c
+++ b/prog/sensord/sensord.c
@@ -233,16 +233,20 @@ int main(int argc, char **argv)
parseChips(argc, argv))
exit(EXIT_FAILURE);
- if (loadLib(sensord_args.cfgFile))
+ if (loadLib(sensord_args.cfgFile)) {
+ freeChips();
exit(EXIT_FAILURE);
+ }
if (!sensord_args.doCGI)
openLog();
if (sensord_args.rrdFile) {
ret = rrdInit();
- if (ret)
+ if (ret) {
+ freeChips();
exit(EXIT_FAILURE);
+ }
}
if (sensord_args.doCGI) {
@@ -253,6 +257,7 @@ int main(int argc, char **argv)
undaemonize();
}
+ freeChips();
if (unloadLib())
exit(EXIT_FAILURE);
diff --git a/prog/sensord/sensord.h b/prog/sensord/sensord.h
index cc9749a7..64c68557 100644
--- a/prog/sensord/sensord.h
+++ b/prog/sensord/sensord.h
@@ -31,6 +31,7 @@ extern void sensorLog(int priority, const char *fmt, ...);
extern int parseArgs(int argc, char **argv);
extern int parseChips(int argc, char **argv);
+extern void freeChips(void);
/* from lib.c */
diff --git a/prog/sensors/main.c b/prog/sensors/main.c
index c38d7e1e..7321a4b4 100644
--- a/prog/sensors/main.c
+++ b/prog/sensors/main.c
@@ -334,6 +334,7 @@ int main(int argc, char *argv[])
goto exit;
}
cnt += do_the_real_work(&chip, &err);
+ sensors_free_chip_name(&chip);
}
if (!cnt) {