diff --git a/antispam-plugin.c b/antispam-plugin.c
index 103b5fb..76ced7b 100644
--- a/antispam-plugin.c
+++ b/antispam-plugin.c
@@ -90,7 +90,7 @@ static bool mailbox_patternmatch(struct mailbox *box,
 		return FALSE;
 #endif
 
-	t_push();
+	T_BEGIN {
 
 	boxname = mailbox_get_name(box);
 	if (lowercase) {
@@ -110,7 +110,7 @@ static bool mailbox_patternmatch(struct mailbox *box,
 
 	rc = memcmp(name, boxname, len) == 0;
 
-	t_pop();
+	} T_END;
 
 	return rc;
 }
@@ -257,7 +257,7 @@ static int parse_folder_setting(const struct antispam_config *cfg,
 	int cnt = 0;
 	enum match_type i;
 
-	t_push();
+	T_BEGIN {
 
 	for (i = 0; i < NUM_MT; ++i) {
 		tmp = getenv(t_strconcat(setting, match_info[i].suffix, NULL),
@@ -286,7 +286,7 @@ static int parse_folder_setting(const struct antispam_config *cfg,
 		}
 	}
 
-	t_pop();
+	} T_END;
 
 	if (!cnt)
 		debug(&cfg->dbgcfg, "no %s folders\n", display_name);
diff --git a/antispam-storage-1.1.c b/antispam-storage-1.1.c
index f28a0cf..aab23d9 100644
--- a/antispam-storage-1.1.c
+++ b/antispam-storage-1.1.c
@@ -508,10 +508,10 @@ void antispam_mail_storage_created(struct mail_storage *storage)
 
 static const char *_getenv(const char *env, void *data ATTR_UNUSED)
 {
-	t_push();
+	T_BEGIN {
 	env = t_str_ucase(t_strconcat("antispam_", env, NULL));
 	env = getenv(env);
-	t_pop();
+	} T_END;
 
 	return env;
 }
diff --git a/antispam-storage-1.2.c b/antispam-storage-1.2.c
index 5e0cb97..269a373 100644
--- a/antispam-storage-1.2.c
+++ b/antispam-storage-1.2.c
@@ -498,10 +498,10 @@ void antispam_mail_storage_created(struct mail_storage *storage)
 
 static const char *_getenv(const char *env, void *data ATTR_UNUSED)
 {
-	t_push();
+	T_BEGIN {
 	env = t_str_ucase(t_strconcat("antispam_", env, NULL));
 	env = getenv(env);
-	t_pop();
+	} T_END;
 
 	return env;
 }
diff --git a/antispam-storage-2.0.c b/antispam-storage-2.0.c
index 3e67553..c3d6251 100644
--- a/antispam-storage-2.0.c
+++ b/antispam-storage-2.0.c
@@ -494,11 +494,11 @@ static const char *_getenv(const char *name, void *data)
 	struct mail_user *user = data;
 	const char *env;
 
-	t_push();
+	T_BEGIN {
 	env = t_strconcat("antispam_", t_str_lcase(name), NULL);
 
 	env = mail_user_plugin_getenv(user, env);
-	t_pop();
+	} T_END;
 
 	return env;
 }
diff --git a/crm114-exec.c b/crm114-exec.c
index 5b39ca9..d786e04 100644
--- a/crm114-exec.c
+++ b/crm114-exec.c
@@ -113,7 +113,7 @@ static int call_reaver(const struct antispam_config *cfg,
 
 		debugv(&cfg->dbgcfg, argv);
 
-		t_push();
+		T_BEGIN {
 		for (i = 0; i < cfg->crm.extra_env_num; i++) {
 			char *name, *value;
 			name = t_strdup_noconst(cfg->crm.extra_env[i]);
@@ -124,7 +124,7 @@ static int call_reaver(const struct antispam_config *cfg,
 			}
 			setenv(name, value, 1);
 		}
-		t_pop();
+		} T_END;
 
 		execv(cfg->crm.reaver_binary, argv);
 		/* fall through if reaver can't be found */
diff --git a/debug.c b/debug.c
index d2683fa..7a2353a 100644
--- a/debug.c
+++ b/debug.c
@@ -14,7 +14,7 @@ static void _debug(const struct antispam_debug_config *cfg,
 	if (cfg->target == ADT_NONE)
 		return;
 
-	t_push();
+	T_BEGIN {
 
 	fmt = t_strconcat("antispam: ", format, NULL);
 
@@ -30,7 +30,7 @@ static void _debug(const struct antispam_debug_config *cfg,
 		break;
 	}
 
-	t_pop();
+	} T_END;
 }
 
 void debug(const struct antispam_debug_config *cfg, const char *fmt, ...)
@@ -48,7 +48,7 @@ void debugv(const struct antispam_debug_config *cfg, char **args)
 	char *buf;
 	const char *str;
 
-	t_push();
+	T_BEGIN {
 	buf = t_buffer_get(buflen);
 
 	while (1) {
@@ -72,7 +72,7 @@ void debugv(const struct antispam_debug_config *cfg, char **args)
 	t_buffer_alloc(pos);
 
 	debug(cfg, "%s", buf);
-	t_pop();
+	} T_END;
 }
 
 void debugv_not_stderr(const struct antispam_debug_config *cfg, char **args)
diff --git a/dspam-exec.c b/dspam-exec.c
index 2e353ce..856babb 100644
--- a/dspam-exec.c
+++ b/dspam-exec.c
@@ -141,7 +141,7 @@ static int call_dspam(const struct antispam_config *cfg,
 		 */
 		debugv_not_stderr(&cfg->dbgcfg, argv);
 
-		t_push();
+		T_BEGIN {
 		for (i = 0; i < cfg->dspam.extra_env_num; i++) {
 			char *name, *value;
 			name = t_strdup_noconst(cfg->dspam.extra_env[i]);
@@ -152,7 +152,7 @@ static int call_dspam(const struct antispam_config *cfg,
 			}
 			setenv(name, value, 1);
 		}
-		t_pop();
+		} T_END;
 
 		execv(cfg->dspam.binary, argv);
 		debug(&cfg->dbgcfg, "executing %s failed: %d (uid=%d, gid=%d)",
diff --git a/pipe.c b/pipe.c
index a20b4aa..2747e47 100644
--- a/pipe.c
+++ b/pipe.c
@@ -136,7 +136,7 @@ static int process_tmpdir(const struct antispam_config *cfg,
 	enum classification wanted;
 	int rc = 0;
 
-	t_push();
+	T_BEGIN {
 
 	buf = t_malloc(20 + ast->tmplen);
 
@@ -159,7 +159,7 @@ static int process_tmpdir(const struct antispam_config *cfg,
 		close(fd);
 	}
 
-	t_pop();
+	} T_END;
 
 	return rc;
 }
@@ -168,7 +168,7 @@ static void clear_tmpdir(struct antispam_transaction_context *ast)
 {
 	char *buf;
 
-	t_push();
+	T_BEGIN {
 
 	buf = t_malloc(20 + ast->tmplen);
 
@@ -180,7 +180,7 @@ static void clear_tmpdir(struct antispam_transaction_context *ast)
 	}
 	rmdir(ast->tmpdir);
 
-	t_pop();
+	} T_END;
 }
 
 static void backend_rollback(const struct antispam_config *cfg ATTR_UNUSED,
@@ -250,7 +250,7 @@ static int backend_handle_mail(const struct antispam_config *cfg,
 		return -1;
 	}
 
-	t_push();
+	T_BEGIN {
 
 	buf = t_malloc(20 + ast->tmplen);
 	i_snprintf(buf, 20 + ast->tmplen - 1, "%s/%d", ast->tmpdir, ast->count);
@@ -312,7 +312,7 @@ static int backend_handle_mail(const struct antispam_config *cfg,
  out_close:
 	close(fd);
  out:
-	t_pop();
+	} T_POP;
 
 	return ret;
 }
diff --git a/spool2dir.c b/spool2dir.c
index cbd1909..d8c9454 100644
--- a/spool2dir.c
+++ b/spool2dir.c
@@ -165,7 +165,7 @@ static int backend_handle_mail(const struct antispam_config *cfg,
 		return -1;
 	}
 
-	t_push();
+	T_BEGIN {
 
 	/* atomically create a _new_ file */
 	while (ast->count <= 9999) {
@@ -174,9 +174,6 @@ static int backend_handle_mail(const struct antispam_config *cfg,
 		if (fd >= 0 || errno != EEXIST)
 			break;
 		/* current filename in buf already exists, zap it */
-		t_pop();
-		t_push();
-		/* buf is invalid now! */
 	}
 
 	if (fd < 0) {
@@ -226,7 +223,7 @@ static int backend_handle_mail(const struct antispam_config *cfg,
 	if (ret)
 		unlink(buf);
  out:
-	t_pop();
+	} T_END;
 
 	return ret;
 }
