[PATCH 4/6] Clean up on libsensors init error

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Clean up if something goes wrong during initialization. Otherwise
we're leaking memory.

---
 lib/init.c |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

--- lm-sensors-3.orig/lib/init.c	2007-10-20 16:08:42.000000000 +0200
+++ lm-sensors-3/lib/init.c	2007-10-20 16:25:19.000000000 +0200
@@ -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)


-- 
Jean Delvare




[Index of Archives]     [Linux Kernel]     [Linux Hardware Monitoring]     [Linux USB Devel]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Yosemite Backpacking]

  Powered by Linux