diff --git a/src/lib-managesieve/managesieve-parser.c b/src/lib-managesieve/managesieve-parser.c
index d05888a5f9aef6b301d345f697fdddc85ab5e639..d36c8640bc443c22f629a9f06b2b794f89ec4d77 100644
--- a/src/lib-managesieve/managesieve-parser.c
+++ b/src/lib-managesieve/managesieve-parser.c
@@ -648,7 +648,7 @@ static ssize_t quoted_string_istream_read(struct istream_private *stream)
 	}
 
 	/* Allocate buffer space */
-	if (!i_stream_get_buffer_space(stream, size, NULL))
+	if (!i_stream_try_alloc(stream, size, NULL))
 		return -2;
 
 	/* Parse quoted string content */
diff --git a/src/lib-sieve-tool/mail-raw.c b/src/lib-sieve-tool/mail-raw.c
index eec30a75961dc0468fa8bacec812a37aba3c1cf0..1ca0f1f10538ec84ea802515d16294ecd0b76e91 100644
--- a/src/lib-sieve-tool/mail-raw.c
+++ b/src/lib-sieve-tool/mail-raw.c
@@ -9,7 +9,6 @@
 #include "str-sanitize.h"
 #include "strescape.h"
 #include "safe-mkstemp.h"
-#include "close-keep-errno.h"
 #include "mkdir-parents.h"
 #include "abspath.h"
 #include "message-address.h"
@@ -88,7 +87,7 @@ static int seekable_fd_callback
 	if (unlink(str_c(path)) < 0) {
 		/* shouldn't happen.. */
 		i_error("unlink(%s) failed: %m", str_c(path));
-		close_keep_errno(fd);
+		i_close_fd(&fd);
 		return -1;
 	}
 
diff --git a/src/lib-sieve/edit-mail.c b/src/lib-sieve/edit-mail.c
index ef4c80bc5bb22fa0d22724ad5258e25cb78175c0..cad2d8264291a685beb48fde7bee7b45b59b48af 100644
--- a/src/lib-sieve/edit-mail.c
+++ b/src/lib-sieve/edit-mail.c
@@ -534,11 +534,9 @@ static inline char *_header_decode
 	/* hdr_data is already unfolded */
 
 	/* Decode MIME encoded-words. */
-	if ( message_header_decode_utf8
-		((const unsigned char *)hdr_data, hdr_data_len, str, FALSE))
-		return i_strdup(str_c(str));
-
-	return i_strndup(hdr_data, hdr_data_len);
+	message_header_decode_utf8
+		((const unsigned char *)hdr_data, hdr_data_len, str, FALSE);
+	return i_strdup(str_c(str));
 }
 
 static int edit_mail_headers_parse