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)