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