Formatting .c/.h files and fix memory leakage issues

Signed-off-by: John Chung <john.chung@arm.com>
Change-Id: Id8328f412c2724992d80c0b3f895c8f85bc4ae68
diff --git a/generator/cper-generate-cli.c b/generator/cper-generate-cli.c
index f5b0c85..185702c 100644
--- a/generator/cper-generate-cli.c
+++ b/generator/cper-generate-cli.c
@@ -40,8 +40,9 @@
 			sections = malloc(sizeof(char *) * num_sections);
 			i++;
 
-			for (int j = i; j < argc; j++)
+			for (int j = i; j < argc; j++) {
 				sections[j - i] = argv[j];
+			}
 			break;
 		} else {
 			printf("Unrecognised argument '%s'. For command information, refer to 'cper-generate --help'.\n",
@@ -53,6 +54,9 @@
 	//If no output file passed as argument, exit.
 	if (out_file == NULL) {
 		printf("No output file provided. For command information, refer to 'cper-generate --help'.\n");
+		if (sections) {
+			free(sections);
+		}
 		return -1;
 	}
 
@@ -61,6 +65,9 @@
 	if (cper_file == NULL) {
 		printf("Could not get a handle for output file '%s', file handle returned null.\n",
 		       out_file);
+		if (sections) {
+			free(sections);
+		}
 		return -1;
 	}
 
@@ -72,13 +79,17 @@
 	} else {
 		//Invalid arguments.
 		printf("Invalid argument. Either both '--sections' and '--single-section' were set, or neither. For command information, refer to 'cper-generate --help'.\n");
+		if (sections) {
+			free(sections);
+		}
 		return -1;
 	}
 
 	//Close & free remaining resources.
 	fclose(cper_file);
-	if (sections != NULL)
+	if (sections != NULL) {
 		free(sections);
+	}
 }
 
 //Prints command help for this CPER generator.
@@ -91,10 +102,10 @@
 	printf("\tWhen the '--single-section' flag is set, the next argument is the single section that should be generated, and\n");
 	printf("\ta single section (no header, only a section descriptor & section) CPER file is generated.\n\n");
 	printf("\tValid section type names are the following:\n");
-	for (int i=0; i<generator_definitions_len; i++) {
+	for (size_t i = 0; i < generator_definitions_len; i++) {
 		printf("\t\t- %s\n", generator_definitions[i].ShortName);
 	}
 	printf("\t\t- unknown\n");
 	printf("\n:: --help\n");
 	printf("\tDisplays help information to the console.\n");
-}
\ No newline at end of file
+}