From 807f5c2e69e14b87dc0800c9e39630780bd6a7cf Mon Sep 17 00:00:00 2001
From: Benno Schulenberg <bensberg@telfort.nl>
Date: Wed, 16 Aug 2017 17:16:18 +0200
Subject: [PATCH] tweaks: do not leak the indentation when all lines are empty

---
 src/text.c | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/src/text.c b/src/text.c
index 41d827f1..66515e48 100644
--- a/src/text.c
+++ b/src/text.c
@@ -296,6 +296,18 @@ void do_indent(void)
 	bot = top;
     }
 
+    /* Go through the lines to see if there's a non-empty one. */
+    for (f = top; f != bot->next; f = f->next) {
+	if (f->data[0] != '\0')
+	    break;
+    }
+
+    /* If all lines are empty, there is nothing to do. */
+    if (f == bot->next) {
+	free(line_indent);
+	return;
+    }
+
     /* Set the indentation to either a bunch of spaces or a single tab. */
     if (ISSET(TABS_TO_SPACES)) {
 	charset(line_indent, ' ', tabsize);
@@ -307,16 +319,6 @@ void do_indent(void)
 
     line_indent[line_indent_len] = '\0';
 
-    /* Go through the lines to see if there's a non-empty one. */
-    for (f = top; f != bot->next; f = f->next) {
-	if (f->data[0] != '\0')
-	    break;
-    }
-
-    /* If all lines are empty, there is nothing to do. */
-    if (f == bot->next)
-	return;
-
     /* Go through each of the lines, but skip empty ones. */
     for (f = top; f != bot->next; f = f->next) {
 	size_t line_len = strlen(f->data);
-- 
GitLab