aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2022-10-27 13:24:35 -0400
committerBruce Hill <bruce@bruce-hill.com>2022-10-27 13:24:35 -0400
commit3fdd5211d96952989fbd7b0cfacd30628c6ab57c (patch)
tree505dbd4be5f4ea89f211e4d05eeba2e023aa46fd
parente258645a523c5fb4407be4a9e90df1314b225191 (diff)
Facilitate memory cleanup
-rw-r--r--Lua/lbp.c6
-rw-r--r--match.c6
-rw-r--r--match.h2
3 files changed, 8 insertions, 6 deletions
diff --git a/Lua/lbp.c b/Lua/lbp.c
index 7c5db3e..462995d 100644
--- a/Lua/lbp.c
+++ b/Lua/lbp.c
@@ -33,9 +33,11 @@ static void push_match(lua_State *L, match_t *m, const char *start);
lua_State *cur_state = NULL;
-static void match_error(const char *msg)
+static void match_error(char **msg)
{
- lua_pushstring(cur_state, msg);
+ lua_pushstring(cur_state, *msg);
+ free(*msg);
+ *msg = NULL;
lua_error(cur_state);
}
diff --git a/match.c b/match.c
index a7b9799..2aa6054 100644
--- a/match.c
+++ b/match.c
@@ -51,8 +51,8 @@ typedef struct match_ctx_s {
static match_t *unused_matches = NULL;
static match_t *in_use_matches = NULL;
-static void default_error_handler(const char *msg) {
- errx(EXIT_FAILURE, "%s", msg);
+static void default_error_handler(char **msg) {
+ errx(EXIT_FAILURE, "%s", *msg);
}
static bp_errhand_t error_handler = default_error_handler;
@@ -881,7 +881,7 @@ bool next_match(match_t **m, const char *start, const char *end, pat_t *pat, pat
cache_destroy(&ctx);
*m = NULL;
if (error_handler)
- error_handler(error_message);
+ error_handler(&error_message);
if (error_message) {
free(error_message);
diff --git a/match.h b/match.h
index 9ead032..c873420 100644
--- a/match.h
+++ b/match.h
@@ -25,7 +25,7 @@ typedef struct match_s {
struct match_s *_children[3];
} match_t;
-typedef void (*bp_errhand_t)(const char *err_msg);
+typedef void (*bp_errhand_t)(char **err_msg);
__attribute__((nonnull))
void recycle_match(match_t **at_m);