mirror of
https://github.com/lm-sensors/lm-sensors.git
synced 2026-11-03 13:38:25 +00:00
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/branches/lm-sensors-2.10@5738 7894878c-1315-0410-8ee3-d5d059ff63e0
This commit is contained in:
1 parent
faf6630897
commit
02dcea3cde
5 files changed
+31
-1
No files matched your search
@@ -7,6 +7,8 @@ SVN-HEAD
|
||||
Module i2c-amd8111: Fix timeout handling (2.6 backport)
|
||||
Module i2c-piix4: ATI SB800 is not actually supported
|
||||
Module it87: Properly decode -128 degrees C (2.6 backport)
|
||||
Program sensord: Fix a memory leak when a chip name is provided
|
||||
Program sensors: Fix a memory leak when a chip name is provided
|
||||
Program sensors-detect: Fix detection of older DS1621
|
||||
|
||||
2.10.8 (20081216)
|
||||
|
||||
@@ -298,6 +298,8 @@ parseChips
|
||||
char *arg = argv[optind + i];
|
||||
if ((err = sensors_parse_chip_name (arg, chipNames + i))) {
|
||||
fprintf (stderr, "Invalid chip name `%s': %s\n", arg, sensors_strerror (err));
|
||||
for (-- i; i >= 0; -- i)
|
||||
free (chipNames[i].prefix);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@@ -305,3 +307,11 @@ parseChips
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
freeChips
|
||||
() {
|
||||
int i;
|
||||
for (i = 0; i < numChipNames; ++ i)
|
||||
free (chipNames[i].prefix);
|
||||
}
|
||||
@@ -199,8 +199,10 @@ main
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
if (initLib () ||
|
||||
loadLib ())
|
||||
loadLib ()) {
|
||||
freeChips ();
|
||||
exit (EXIT_FAILURE);
|
||||
}
|
||||
|
||||
if (isDaemon)
|
||||
openLog ();
|
||||
@@ -225,6 +227,7 @@ main
|
||||
ret = readChips ();
|
||||
}
|
||||
|
||||
freeChips ();
|
||||
if (unloadLib ())
|
||||
exit (EXIT_FAILURE);
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ extern int numChipNames;
|
||||
|
||||
extern int parseArgs (int argc, char **argv);
|
||||
extern int parseChips (int argc, char **argv);
|
||||
extern void freeChips ();
|
||||
|
||||
/* from lib.c */
|
||||
|
||||
|
||||
@@ -92,6 +92,14 @@ void print_version(void)
|
||||
printf("%s version %s with libsensors version %s\n", PROGRAM, VERSION, libsensors_version);
|
||||
}
|
||||
|
||||
void free_chip_names()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < chips_count; i++)
|
||||
free(chips[i].prefix);
|
||||
}
|
||||
|
||||
/* This examines global var config_file, and leaves the name there too.
|
||||
It also opens config_file. */
|
||||
static void open_config_file(const char* config_file_name)
|
||||
@@ -105,6 +113,7 @@ static void open_config_file(const char* config_file_name)
|
||||
if (!config_file) {
|
||||
fprintf(stderr, "Could not open config file\n");
|
||||
perror(config_file_name);
|
||||
free_chip_names();
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
@@ -221,10 +230,12 @@ int main (int argc, char *argv[])
|
||||
for(i = optind; i < argc; i++)
|
||||
if ((res = sensors_parse_chip_name(argv[i],chips+chips_count))) {
|
||||
fprintf(stderr,"Parse error in chip name `%s'\n",argv[i]);
|
||||
free_chip_names();
|
||||
print_short_help();
|
||||
exit(1);
|
||||
} else if (++chips_count == CHIPS_MAX) {
|
||||
fprintf(stderr,"Too many chips on command line!\n");
|
||||
free_chip_names();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
@@ -238,6 +249,7 @@ int main (int argc, char *argv[])
|
||||
"Kernel interface access error\n"
|
||||
"For 2.6 kernels, make sure you have mounted sysfs and libsensors\n"
|
||||
"was compiled with sysfs support!\n");
|
||||
free_chip_names();
|
||||
sensors_cleanup();
|
||||
exit(1);
|
||||
}
|
||||
@@ -246,6 +258,7 @@ int main (int argc, char *argv[])
|
||||
set_degstr();
|
||||
|
||||
if(do_the_real_work(&error)) {
|
||||
free_chip_names();
|
||||
sensors_cleanup();
|
||||
exit(error);
|
||||
} else {
|
||||
@@ -256,6 +269,7 @@ int main (int argc, char *argv[])
|
||||
"Try sensors-detect to find out which these are.\n");
|
||||
else
|
||||
fprintf(stderr,"Specified sensor(s) not found!\n");
|
||||
free_chip_names();
|
||||
sensors_cleanup();
|
||||
exit(1);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user