mirror of
https://github.com/lm-sensors/lm-sensors
synced 2025-09-02 15:25:38 +00:00
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
This commit is contained in:
3
CHANGES
3
CHANGES
@@ -5,6 +5,7 @@ SVN-HEAD
|
|||||||
isadump: Use geteuid instead of getuid so that setuid bit works
|
isadump: Use geteuid instead of getuid so that setuid bit works
|
||||||
isaset: 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
|
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
|
Makefile: Include generated source files in dependency checking
|
||||||
Make it possible to skip building of the static library
|
Make it possible to skip building of the static library
|
||||||
fancontrol: Add support for absolute path to hwmon devices
|
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
|
Don't use the system log when generating a CGI script
|
||||||
Disable unit scaling for fan speeds
|
Disable unit scaling for fan speeds
|
||||||
Use daemon logging facility instead of local4 by default
|
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
|
sensors-detect: Add nNidia nForce MCP78S SMBus detection
|
||||||
Display Super-I/O address even if LD is disabled
|
Display Super-I/O address even if LD is disabled
|
||||||
Differentiate between PC8374L and WPCD377I
|
Differentiate between PC8374L and WPCD377I
|
||||||
|
@@ -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
|
authors can quickly figure out how to test for the availability of a
|
||||||
given new feature.
|
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
|
0x410 lm-sensors 3.1.0
|
||||||
* Added bus type "acpi":
|
* Added bus type "acpi":
|
||||||
#define SENSORS_BUS_TYPE_ACPI
|
#define SENSORS_BUS_TYPE_ACPI
|
||||||
|
@@ -54,6 +54,11 @@ sensors_bus *sensors_proc_bus = NULL;
|
|||||||
int sensors_proc_bus_count = 0;
|
int sensors_proc_bus_count = 0;
|
||||||
int sensors_proc_bus_max = 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:
|
Parse a chip name to the internal representation. These are valid names:
|
||||||
|
|
||||||
|
@@ -42,6 +42,7 @@ libsensors \- publicly accessible functions provided by the sensors library
|
|||||||
/* Chip name handling */
|
/* Chip name handling */
|
||||||
.BI "int sensors_parse_chip_name(const char *" orig_name ","
|
.BI "int sensors_parse_chip_name(const char *" orig_name ","
|
||||||
.BI " sensors_chip_name *" res ");"
|
.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 "int sensors_snprintf_chip_name(char *" str ", size_t " size ","
|
||||||
.BI " const sensors_chip_name *" chip ");"
|
.BI " const sensors_chip_name *" chip ");"
|
||||||
.BI "const char *sensors_get_adapter_name(const sensors_bus_id *" bus ");"
|
.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()
|
.B sensors_parse_chip_name()
|
||||||
parses a chip name to the internal representation. Return 0 on success,
|
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()
|
.B sensors_snprintf_chip_name()
|
||||||
prints a chip name from its internal representation. Note that chip should
|
prints a chip name from its internal representation. Note that chip should
|
||||||
|
@@ -31,7 +31,7 @@
|
|||||||
when the API + ABI breaks), the third digit is incremented to track small
|
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
|
API additions like new flags / enum values. The second digit is for tracking
|
||||||
larger additions like new methods. */
|
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_PREFIX_ANY NULL
|
||||||
#define SENSORS_CHIP_NAME_ADDR_ANY (-1)
|
#define SENSORS_CHIP_NAME_ADDR_ANY (-1)
|
||||||
@@ -80,6 +80,9 @@ void sensors_cleanup(void);
|
|||||||
on error. */
|
on error. */
|
||||||
int sensors_parse_chip_name(const char *orig_name, sensors_chip_name *res);
|
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
|
/* Print a chip name from its internal representation. Note that chip should
|
||||||
not contain wildcard values! Return the number of characters printed on
|
not contain wildcard values! Return the number of characters printed on
|
||||||
success (same as snprintf), <0 on error. */
|
success (same as snprintf), <0 on error. */
|
||||||
|
@@ -255,6 +255,8 @@ int parseChips(int argc, char **argv)
|
|||||||
if (err) {
|
if (err) {
|
||||||
fprintf(stderr, "Invalid chip name `%s': %s\n", arg,
|
fprintf(stderr, "Invalid chip name `%s': %s\n", arg,
|
||||||
sensors_strerror(err));
|
sensors_strerror(err));
|
||||||
|
for (i--; i >= 0; i--)
|
||||||
|
sensors_free_chip_name(sensord_args.chipNames + i);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -262,3 +264,11 @@ int parseChips(int argc, char **argv)
|
|||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void freeChips()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
|
for (i = 0; i < sensord_args.numChipNames; i++)
|
||||||
|
sensors_free_chip_name(sensord_args.chipNames + i);
|
||||||
|
}
|
||||||
|
@@ -233,16 +233,20 @@ int main(int argc, char **argv)
|
|||||||
parseChips(argc, argv))
|
parseChips(argc, argv))
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
if (loadLib(sensord_args.cfgFile))
|
if (loadLib(sensord_args.cfgFile)) {
|
||||||
|
freeChips();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
if (!sensord_args.doCGI)
|
if (!sensord_args.doCGI)
|
||||||
openLog();
|
openLog();
|
||||||
|
|
||||||
if (sensord_args.rrdFile) {
|
if (sensord_args.rrdFile) {
|
||||||
ret = rrdInit();
|
ret = rrdInit();
|
||||||
if (ret)
|
if (ret) {
|
||||||
|
freeChips();
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (sensord_args.doCGI) {
|
if (sensord_args.doCGI) {
|
||||||
@@ -253,6 +257,7 @@ int main(int argc, char **argv)
|
|||||||
undaemonize();
|
undaemonize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
freeChips();
|
||||||
if (unloadLib())
|
if (unloadLib())
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
|
|
||||||
|
@@ -31,6 +31,7 @@ extern void sensorLog(int priority, const char *fmt, ...);
|
|||||||
|
|
||||||
extern int parseArgs(int argc, char **argv);
|
extern int parseArgs(int argc, char **argv);
|
||||||
extern int parseChips(int argc, char **argv);
|
extern int parseChips(int argc, char **argv);
|
||||||
|
extern void freeChips(void);
|
||||||
|
|
||||||
/* from lib.c */
|
/* from lib.c */
|
||||||
|
|
||||||
|
@@ -334,6 +334,7 @@ int main(int argc, char *argv[])
|
|||||||
goto exit;
|
goto exit;
|
||||||
}
|
}
|
||||||
cnt += do_the_real_work(&chip, &err);
|
cnt += do_the_real_work(&chip, &err);
|
||||||
|
sensors_free_chip_name(&chip);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!cnt) {
|
if (!cnt) {
|
||||||
|
Reference in New Issue
Block a user