diff --git a/src/lib-sieve/plugins/include/ext-include-common.c b/src/lib-sieve/plugins/include/ext-include-common.c
index 2b027e59260aa5de9b1654dbab73b8292ec60d96..56c96a1d7fe266cd1735df30f821db7b0906792b 100644
--- a/src/lib-sieve/plugins/include/ext-include-common.c
+++ b/src/lib-sieve/plugins/include/ext-include-common.c
@@ -164,7 +164,7 @@ struct ext_include_ast_context *ext_include_create_ast_context
 
 		sieve_variable_scope_ref(actx->global_vars);
 	} else {
-		actx->global_vars = sieve_variable_scope_create(this_ext);			
+		actx->global_vars = sieve_variable_scope_create(this_ext->svinst, this_ext);			
 	}
 
 	sieve_ast_extension_register
diff --git a/src/lib-sieve/plugins/variables/ext-variables-common.c b/src/lib-sieve/plugins/variables/ext-variables-common.c
index 8140ebca9c4f13ec98e77e18b0e7dea9fb9a4653..70ae54614aeddcad36dd1eedcbeae3bc3e30d3e2 100644
--- a/src/lib-sieve/plugins/variables/ext-variables-common.c
+++ b/src/lib-sieve/plugins/variables/ext-variables-common.c
@@ -42,10 +42,11 @@ struct sieve_variable_scope {
 	pool_t pool;
 	int refcount;
 
-	struct sieve_variable *error_var;
-
+	struct sieve_instance *svinst;
 	const struct sieve_extension *ext;
 
+	struct sieve_variable *error_var;
+
 	struct hash_table *variables;
 	ARRAY_DEFINE(variable_index, struct sieve_variable *);
 };
@@ -64,7 +65,7 @@ struct sieve_variable_scope_iter {
 };
 
 struct sieve_variable_scope *sieve_variable_scope_create
-(const struct sieve_extension *ext) 
+(struct sieve_instance *svinst, const struct sieve_extension *ext) 
 {
 	struct sieve_variable_scope *scope;
 	pool_t pool;
@@ -74,6 +75,7 @@ struct sieve_variable_scope *sieve_variable_scope_create
 	scope->pool = pool;
 	scope->refcount = 1;
 
+	scope->svinst = svinst;
 	scope->ext = ext;
 
 	scope->variables = hash_table_create
@@ -234,7 +236,7 @@ struct sieve_variable *sieve_variable_scope_get_indexed
 /* Scope binary */
 
 struct sieve_variable_scope *sieve_variable_scope_binary_dump
-(const struct sieve_extension *ext, 
+(struct sieve_instance *svinst, const struct sieve_extension *ext, 
 	const struct sieve_dumptime_env *denv, sieve_size_t *address)
 {
 	struct sieve_variable_scope *local_scope;
@@ -253,7 +255,7 @@ struct sieve_variable_scope *sieve_variable_scope_binary_dump
 		return FALSE;
 	
 	/* Create scope */
-	local_scope = sieve_variable_scope_create(ext);
+	local_scope = sieve_variable_scope_create(svinst, ext);
 	
 	/* Read and dump scope itself */
 
@@ -336,7 +338,7 @@ struct sieve_variable_scope_binary *sieve_variable_scope_binary_read
 	}
 	
 	/* Create scope */
-	scope = sieve_variable_scope_create(ext);
+	scope = sieve_variable_scope_create(svinst, ext);
 
 	scpbin = sieve_variable_scope_binary_create(scope);
 	scpbin->size = scope_size;
@@ -352,7 +354,7 @@ struct sieve_variable_scope *sieve_variable_scope_binary_get
 (struct sieve_variable_scope_binary *scpbin)
 {
 	const struct sieve_extension *ext = scpbin->scope->ext;
-	struct sieve_instance *svinst = ext->svinst;
+	struct sieve_instance *svinst = scpbin->scope->svinst;
 	const char *ext_name = 
 		( ext == NULL ? "variables" : sieve_extension_name(ext) );
 	unsigned int i;
@@ -551,7 +553,7 @@ static struct sieve_variable_scope *ext_variables_create_local_scope
 {
 	struct sieve_variable_scope *scope;
 
-	scope = sieve_variable_scope_create(NULL);
+	scope = sieve_variable_scope_create(this_ext->svinst, NULL);
 
 	sieve_ast_extension_register
 		(ast, this_ext, &variables_ast_extension, (void *) scope);
diff --git a/src/lib-sieve/plugins/variables/ext-variables-dump.c b/src/lib-sieve/plugins/variables/ext-variables-dump.c
index a102dd3e9456ec24933a5e141f3b815583624506..d91cc04692bb389e8df1414a6a1d775f59aab79e 100644
--- a/src/lib-sieve/plugins/variables/ext-variables-dump.c
+++ b/src/lib-sieve/plugins/variables/ext-variables-dump.c
@@ -73,7 +73,8 @@ bool ext_variables_code_dump
 	struct ext_variables_dump_context *dctx;
 	struct sieve_variable_scope *local_scope;
 
-	local_scope = sieve_variable_scope_binary_dump(NULL, denv, address);
+	local_scope = sieve_variable_scope_binary_dump
+		(ext->svinst, NULL, denv, address);
 		
 	dctx = ext_variables_dump_get_context(ext, denv);
 	dctx->local_scope = local_scope;
diff --git a/src/lib-sieve/plugins/variables/sieve-ext-variables.h b/src/lib-sieve/plugins/variables/sieve-ext-variables.h
index 5258e04ad8610c08a000124efef297431a703cd5..0365dd5c52b86d13728e931d9da8db2669de66ef 100644
--- a/src/lib-sieve/plugins/variables/sieve-ext-variables.h
+++ b/src/lib-sieve/plugins/variables/sieve-ext-variables.h
@@ -63,7 +63,7 @@ struct sieve_variable {
 struct sieve_variable_scope;
 
 struct sieve_variable_scope *sieve_variable_scope_create
-	(const struct sieve_extension *ext);
+	(struct sieve_instance *svinst, const struct sieve_extension *ext);
 void sieve_variable_scope_ref
 	(struct sieve_variable_scope *scope);
 void sieve_variable_scope_unref
@@ -91,7 +91,7 @@ void sieve_variable_scope_binary_unref
 	(struct sieve_variable_scope_binary **scpbin);
 
 struct sieve_variable_scope *sieve_variable_scope_binary_dump
-	(const struct sieve_extension *ext, 
+	(struct sieve_instance *svinst, const struct sieve_extension *ext, 
 		const struct sieve_dumptime_env *denv, sieve_size_t *address);
 struct sieve_variable_scope_binary *sieve_variable_scope_binary_read
 	(struct sieve_instance *svinst, const struct sieve_extension *ext,