summaryrefslogtreecommitdiff
path: root/src/tre/ltre.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/tre/ltre.c')
-rw-r--r--src/tre/ltre.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/tre/ltre.c b/src/tre/ltre.c
index 06c66c8..d734434 100644
--- a/src/tre/ltre.c
+++ b/src/tre/ltre.c
@@ -108,6 +108,8 @@ static int compile_regex (lua_State *L, const TArgComp *argC, TPosix **pud) {
if (argC->cflags & REG_NOSUB)
ud->r.re_nsub = 0;
ud->match = (regmatch_t *) Lmalloc (L, (ALG_NSUB(ud) + 1) * sizeof (regmatch_t));
+ if (!ud->match)
+ luaL_error (L, "malloc failed");
lua_pushvalue (L, ALG_ENVIRONINDEX);
lua_setmetatable (L, -2);
@@ -209,7 +211,7 @@ static int Ltre_gc (lua_State *L) {
if (ud->freed == 0) { /* precaution against "manual" __gc calling */
ud->freed = 1;
tre_regfree (&ud->r);
- free (ud->match);
+ Lfree (L, ud->match, (ALG_NSUB(ud) + 1) * sizeof (regmatch_t));
}
return 0;
}