summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohannes Weiner <hannes@cmpxchg.org>2010-08-12 00:16:20 -0400
committerJohannes Weiner <hannes@cmpxchg.org>2010-08-12 00:16:20 -0400
commit1eda99d55687972c411f95a1b6dfa69760e16a34 (patch)
tree24c3114a269e07a0401562c8ec4955658d0843cc
parent3aae5d5624d6c9636a4121c25f258c5a55f00f4d (diff)
libl/regex: protect result list while constructing
Signed-off-by: Johannes Weiner <hannes@cmpxchg.org>
-rw-r--r--lib/regex.c8
1 files changed, 5 insertions, 3 deletions
diff --git a/lib/regex.c b/lib/regex.c
index 88618cb..348e237 100644
--- a/lib/regex.c
+++ b/lib/regex.c
@@ -31,7 +31,6 @@ static sheep_t match(struct sheep_vm *vm, unsigned int nr_args)
if (sheep_unpack_stack(vm, nr_args, "ss", &regex_, &string_))
return NULL;
-
sheep_protect(vm, string_);
regex = sheep_rawstring(regex_);
@@ -41,12 +40,13 @@ static sheep_t match(struct sheep_vm *vm, unsigned int nr_args)
}
result = sheep_make_cons(vm, NULL, NULL);
- string = sheep_rawstring(string_);
+ sheep_protect(vm, result);
+ string = sheep_rawstring(string_);
status = regexec(&reg, string, MAX_MATCHES, matches, 0);
regfree(&reg);
if (status == REG_NOMATCH)
- goto out;
+ goto out_result;
list = sheep_list(result);
for (i = 0; i < MAX_MATCHES && matches[i].rm_so != -1; i++) {
@@ -64,6 +64,8 @@ static sheep_t match(struct sheep_vm *vm, unsigned int nr_args)
list->tail = sheep_make_cons(vm, NULL, NULL);
list = sheep_list(list->tail);
}
+out_result:
+ sheep_unprotect(vm, result);
out:
sheep_unprotect(vm, string_);
return result;