[augeas-devel] [PATCH 11 of 11] Misc leak fixes in the interpreter
David Lutterkort
dlutter at redhat.com
Thu May 15 20:02:01 UTC 2008
1 file changed, 11 insertions(+), 5 deletions(-)
src/syntax.c | 16 +++++++++++-----
# HG changeset patch
# User David Lutterkort <dlutter at redhat.com>
# Date 1210881692 25200
# Node ID d55304a4ad71418a061cf429a6c2e20c309a371b
# Parent e565de2d5b512be20b4f1c17180d7a990c0dc49e
Misc leak fixes in the interpreter
* Do not ref the old binding in bind_type, ownership is transferred from
the caller to the new list head
* Unref the argument of an apply and the func computed in compile_compose
* Unref the value after it is bound in the context in compile_decl
* Unref various things in define_native_intl
diff -r e565de2d5b51 -r d55304a4ad71 src/syntax.c
--- a/src/syntax.c Thu May 15 12:58:58 2008 -0700
+++ b/src/syntax.c Thu May 15 13:01:32 2008 -0700
@@ -537,7 +537,6 @@ static struct binding *bind_type(struct
make_ref(binding->ident);
binding->ident->str = strdup(name);
binding->type = ref(type);
- ref(*bnds);
list_cons(*bnds, binding);
return binding;
@@ -1391,6 +1390,7 @@ static struct value *compile_compose(str
assert(type_equal(func->type, exp->type));
v = make_closure(func, ctx->local);
+ unref(func, term);
} else {
fatal_error(info, "Tried to compose a %s and a %s to yield a %s",
type_name(exp->left->type), type_name(exp->right->type),
@@ -1492,6 +1492,7 @@ static struct value *apply(struct term *
done:
unref(lctx.local, binding);
+ unref(arg, value);
unref(f, value);
return result;
}
@@ -1646,19 +1647,21 @@ static int compile_test(struct term *ter
static int compile_decl(struct term *term, struct ctx *ctx) {
if (term->tag == A_BIND) {
+ int result;
+
struct value *v = compile_exp(term->info, term->exp, ctx);
bind(&ctx->local, term->bname, term->type, v);
- if (!EXN(v))
- return 1;
- if (! v->exn->seen) {
+ if (EXN(v) && !v->exn->seen) {
syntax_error(term->info, "Failed to compile %s",
term->bname);
print_value(stdout, v);
printf("\n");
v->exn->seen = 1;
}
- return 0;
+ result = ! EXN(v);
+ unref(v, value);
+ return result;
} else if (term->tag == A_TEST) {
return compile_test(term, ctx);
}
@@ -1768,6 +1771,9 @@ void define_native_intl(const char *file
}
v = make_closure(func, ctx.local);
bind(&ctx.local, name, func->type, v);
+ unref(v, value);
+ unref(func, term);
+ unref(module->bindings, binding);
module->bindings = ctx.local;
}
More information about the augeas-devel
mailing list