diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2026-08-01 00:08:19 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2026-08-01 13:39:17 +0300 |
| commit | 8f10104f8aae870eea02d5695fe465d3103e2731 (patch) | |
| tree | d11d7f741d6d9ec67dd40a44927875b9876c140d /src | |
| parent | 3b2611bb1b4004bb39df77050f1e31fbf73b084d (diff) | |
| download | fwdscript-8f10104f8aae870eea02d5695fe465d3103e2731.tar.gz fwdscript-8f10104f8aae870eea02d5695fe465d3103e2731.zip | |
free registered functions
Diffstat (limited to 'src')
| -rw-r--r-- | src/fwdscript.c | 17 |
1 files changed, 14 insertions, 3 deletions
diff --git a/src/fwdscript.c b/src/fwdscript.c index c197e2f..3ee7449 100644 --- a/src/fwdscript.c +++ b/src/fwdscript.c @@ -76,7 +76,7 @@ static int fwdhash(const struct fwdval *a) #define MAP_NAME fwdtbl #include <conts/map.h> -#define MAP_KEY const char * +#define MAP_KEY char * #define MAP_TYPE size_t #define MAP_CMP(A, B) strcmp((A), (B)) #define MAP_HASH(A) (A)[0] @@ -111,7 +111,7 @@ struct fwdbuiltin { fwd_typecheck_t tp; }; -#define MAP_KEY const char * +#define MAP_KEY char * #define MAP_TYPE struct fwdbuiltin #define MAP_CMP(A, B) strcmp((A), (B)) #define MAP_HASH(A) (A)[0] @@ -143,11 +143,18 @@ static int fwdscript_register(struct fwdscript *s, const char *name, .tp = tp }; + char *dname = strdup(name); + if (!dname) { + fprintf(stderr, "failed duping register name\n"); + return -1; + } + struct fwdbuiltin *b = fwdbuiltins_insert(&s->builtins, - name, builtin); + dname, builtin); if (b == NULL) { fprintf(stderr, "failed registering %s\n", name); + free(dname); return -1; } @@ -454,6 +461,9 @@ static int fwdscript_run(struct fwdscript *s, const char *name, struct fwdvals * static void fwdscript_destroy(struct fwdscript *s) { + foreach(fwdbuiltins, builtin, &s->builtins) { + free(builtin.t->key); + } fwdfuncs_destroy(&s->funcs); fwdinsns_destroy(&s->insns); fwdbuiltins_destroy(&s->builtins); @@ -481,6 +491,7 @@ int main() fwdscript_run(&inst, "main", &args); + /* string should've been consumed by main so we shouldn't try to free it */ fwdvals_destroy(&args); fwdscript_destroy(&inst); } |
