From 7891d6325941e8a2c7f5a98b955cf976d7642b72 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Fri, 13 Oct 2006 12:43:43 +0000 Subject: [PATCH] sensors: Handle option -c more efficiently. We don't need to strdup() the file names, we can use them directly. As a side effect, this fixes a memory leak which was happening if option -c was specified more than once on the command line. git-svn-id: http://lm-sensors.org/svn/lm-sensors/trunk@4205 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + prog/sensors/main.c | 10 ++-------- 2 files changed, 3 insertions(+), 8 deletions(-) diff --git a/CHANGES b/CHANGES index 77d21a47..2a26483e 100644 --- a/CHANGES +++ b/CHANGES @@ -9,6 +9,7 @@ SVN HEAD Program sensord: Add pc87247 support (fans only) Program sensors: Add pc87247 support (fans only) Hide error on missing f71805f fan + Handle option -c more efficiently Program sensors-detect: Add SMSC DME1737 detection Add EPoX EP1308 detection (Hans Edgington) diff --git a/prog/sensors/main.c b/prog/sensors/main.c index e8a4c54e..086940ff 100644 --- a/prog/sensors/main.c +++ b/prog/sensors/main.c @@ -149,7 +149,7 @@ static void set_degstr(void) int main (int argc, char *argv[]) { int c,res,i,error; - char *config_file_name = NULL; + const char *config_file_name = ETCDIR "/" DEFAULT_CONFIG_FILE_NAME; struct option long_opts[] = { { "help", no_argument, NULL, 'h' }, @@ -187,7 +187,7 @@ int main (int argc, char *argv[]) print_version(); exit(0); case 'c': - config_file_name = strdup(optarg); + config_file_name = optarg; break; case 's': do_sets = 1; @@ -229,11 +229,7 @@ int main (int argc, char *argv[]) exit(1); } - - if (config_file_name == NULL) - config_file_name = strdup(ETCDIR "/" DEFAULT_CONFIG_FILE_NAME); open_config_file(config_file_name); - if ((res = sensors_init(config_file))) { fprintf(stderr,"%s\n",sensors_strerror(res)); if (res == -SENSORS_ERR_PROC) @@ -243,9 +239,7 @@ int main (int argc, char *argv[]) "was compiled with sysfs support!\n"); exit(1); } - close_config_file(config_file_name); - free(config_file_name); /* build the degrees string */ set_degstr();