insmod: fix memory leak

insmod makes a half-successful attempt to clean up on failure.  Let's
make it clean up on all failures, and remember to clean up on success
as well.

This leaves modprobe as the only leaky program, at least for the code
paths executed by the test suite.

Signed-off-by: Alan Jenkins <alan-jenkins@tuffmail.co.uk>
diff --git a/insmod.c b/insmod.c
index 3a2a910..de4f68b 100644
--- a/insmod.c
+++ b/insmod.c
@@ -60,9 +60,7 @@
 {
 	unsigned int max = 16384;
 	int ret, fd, err_save;
-	void *buffer = malloc(max);
-	if (!buffer)
-		return NULL;
+	void *buffer;
 
 	if (streq(filename, "-"))
 		fd = dup(STDIN_FILENO);
@@ -72,6 +70,10 @@
 	if (fd < 0)
 		return NULL;
 
+	buffer = malloc(max);
+	if (!buffer)
+		goto out_error;
+
 	*size = 0;
 	while ((ret = read(fd, buffer + *size, max - *size)) > 0) {
 		*size += ret;
@@ -158,7 +160,10 @@
 	if (ret != 0) {
 		fprintf(stderr, "insmod: error inserting '%s': %li %s\n",
 			filename, ret, moderror(errno));
-		exit(1);
 	}
+	free(file);
+
+	if (ret != 0)
+		exit(1);
 	exit(0);
 }