From 58b3284058e414d453fbb4d1486804a99c7f00a6 Mon Sep 17 00:00:00 2001 From: Jean Delvare Date: Thu, 25 Oct 2007 09:51:19 +0000 Subject: [PATCH] Clean up if something goes wrong during initialization. Otherwise we're leaking memory. git-svn-id: http://lm-sensors.org/svn/lm-sensors/branches/lm-sensors-3.0.0@4988 7894878c-1315-0410-8ee3-d5d059ff63e0 --- CHANGES | 1 + lib/init.c | 15 ++++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/CHANGES b/CHANGES index 82d3fd2b..8498c867 100644 --- a/CHANGES +++ b/CHANGES @@ -3,6 +3,7 @@ lm-sensors CHANGES file SVN HEAD libsensors: Add a default configuration file + Fix memory leaks on initialization error sensord: Reload config on SIGHUP rather than automatically No default configuration file name sensors: Fix file handle leak on library initialization error diff --git a/lib/init.c b/lib/init.c index 15ad3a5a..01c68a88 100644 --- a/lib/init.c +++ b/lib/init.c @@ -39,28 +39,33 @@ int sensors_init(FILE *input) return -SENSORS_ERR_KERNEL; if ((res = sensors_read_sysfs_bus()) || (res = sensors_read_sysfs_chips())) - return res; + goto exit_cleanup; + res = -SENSORS_ERR_PARSE; if (input) { if (sensors_scanner_init(input) || sensors_yyparse()) - return -SENSORS_ERR_PARSE; + goto exit_cleanup; } else { /* No configuration provided, use default */ input = fopen(DEFAULT_CONFIG_FILE, "r"); if (!input) - return -SENSORS_ERR_PARSE; + goto exit_cleanup; if (sensors_scanner_init(input) || sensors_yyparse()) { fclose(input); - return -SENSORS_ERR_PARSE; + goto exit_cleanup; } fclose(input); } if ((res = sensors_substitute_busses())) - return res; + goto exit_cleanup; return 0; + +exit_cleanup: + sensors_cleanup(); + return res; } static void free_chip_name(sensors_chip_name *name)