cca0c4
From 38d8178482ea7dabf7c4ab8c2973faa2b469e9c7 Mon Sep 17 00:00:00 2001
cca0c4
From: Peter Jones <pjones@redhat.com>
cca0c4
Date: Thu, 2 Jul 2015 16:26:59 -0400
cca0c4
Subject: [PATCH 11/55] Don't leak from one extractTitle() call.
cca0c4
cca0c4
Found by coverity.
cca0c4
cca0c4
Signed-off-by: Peter Jones <pjones@redhat.com>
cca0c4
---
cca0c4
 grubby.c | 27 +++++++++++++++++----------
cca0c4
 1 file changed, 17 insertions(+), 10 deletions(-)
cca0c4
cca0c4
diff --git a/grubby.c b/grubby.c
cca0c4
index 0bb486967bf..70477ba14ee 100644
cca0c4
--- a/grubby.c
cca0c4
+++ b/grubby.c
cca0c4
@@ -1510,13 +1510,14 @@ static struct grubConfig * readConfig(const char * inName,
cca0c4
     return cfg;
cca0c4
 }
cca0c4
 
cca0c4
-static void writeDefault(FILE * out, char * indent, 
cca0c4
+static void writeDefault(FILE * out, char * indent,
cca0c4
 			 char * separator, struct grubConfig * cfg) {
cca0c4
     struct singleEntry * entry;
cca0c4
     struct singleLine * line;
cca0c4
     int i;
cca0c4
 
cca0c4
-    if (!cfg->defaultImage && cfg->flags == GRUB_CONFIG_NO_DEFAULT) return;
cca0c4
+    if (!cfg->defaultImage && cfg->flags == GRUB_CONFIG_NO_DEFAULT)
cca0c4
+	return;
cca0c4
 
cca0c4
     if (cfg->defaultImage == DEFAULT_SAVED)
cca0c4
 	fprintf(out, "%sdefault%ssaved\n", indent, separator);
cca0c4
@@ -1540,34 +1541,40 @@ static void writeDefault(FILE * out, char * indent,
cca0c4
 	        fprintf(out, "%sset default=\"%d\"\n", indent,
cca0c4
 			cfg->defaultImage);
cca0c4
 	    } else {
cca0c4
-		fprintf(out, "%sdefault%s%d\n", indent, separator, 
cca0c4
+		fprintf(out, "%sdefault%s%d\n", indent, separator,
cca0c4
 			cfg->defaultImage);
cca0c4
 	    }
cca0c4
 	} else {
cca0c4
 	    int image = cfg->defaultImage;
cca0c4
 
cca0c4
 	    entry = cfg->entries;
cca0c4
-	    while (entry && entry->skip) entry = entry->next;
cca0c4
+	    while (entry && entry->skip)
cca0c4
+		entry = entry->next;
cca0c4
 
cca0c4
 	    i = 0;
cca0c4
 	    while (entry && i < image) {
cca0c4
 		entry = entry->next;
cca0c4
 
cca0c4
-		while (entry && entry->skip) entry = entry->next;
cca0c4
+		while (entry && entry->skip)
cca0c4
+		    entry = entry->next;
cca0c4
 		i++;
cca0c4
 	    }
cca0c4
 
cca0c4
-	    if (!entry) return;
cca0c4
+	    if (!entry)
cca0c4
+		return;
cca0c4
 
cca0c4
 	    line = getLineByType(LT_TITLE, entry->lines);
cca0c4
 
cca0c4
 	    if (line && line->numElements >= 2)
cca0c4
-		fprintf(out, "%sdefault%s%s\n", indent, separator, 
cca0c4
+		fprintf(out, "%sdefault%s%s\n", indent, separator,
cca0c4
 			line->elements[1].item);
cca0c4
-            else if (line && (line->numElements == 1) && 
cca0c4
+            else if (line && (line->numElements == 1) &&
cca0c4
                      cfg->cfi->titleBracketed) {
cca0c4
-		fprintf(out, "%sdefault%s%s\n", indent, separator, 
cca0c4
-                        extractTitle(cfg, line));
cca0c4
+		char *title = extractTitle(cfg, line);
cca0c4
+		if (title) {
cca0c4
+		    fprintf(out, "%sdefault%s%s\n", indent, separator, title);
cca0c4
+		    free(title);
cca0c4
+		}
cca0c4
             }
cca0c4
 	}
cca0c4
     }
cca0c4
-- 
cca0c4
2.17.1
cca0c4