aboutsummaryrefslogtreecommitdiff
path: root/src/builtins.c
diff options
context:
space:
mode:
authorPreston Pan <preston@nullring.xyz>2024-01-20 22:57:11 -0800
committerPreston Pan <preston@nullring.xyz>2024-01-20 22:57:11 -0800
commit0184e51377ebb5e398748f03552abe4168d359f3 (patch)
tree0ae98e7eb4cce00c30e645c12d840cab50ddb508 /src/builtins.c
parent479df1ff2ab4a6cf8f7a42b9b6f4fa4c403590ff (diff)
fix memory leak
Diffstat (limited to 'src/builtins.c')
-rw-r--r--src/builtins.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/src/builtins.c b/src/builtins.c
index 8d985fe..475306d 100644
--- a/src/builtins.c
+++ b/src/builtins.c
@@ -401,12 +401,12 @@ void stemfread(value_t *v) {
eval_error("EMPTY STACK");
return;
}
- char *val = NULL;
- size_t len;
+ char *val = "";
+ size_t len = 0;
FILE *fp = fopen(v1->str_word->value, "rb");
if (!fp) {
array_append(STACK, v1);
- eval_error("INCORRECT TYPE ARGUMENT");
+ eval_error("FREAD ERROR");
return;
}
ssize_t bytes_read = getdelim(&val, &len, '\0', fp);
@@ -593,8 +593,8 @@ void dip(value_t *v) {
return;
}
+ array_append(EVAL_STACK, v1);
if (v2->type == VQUOTE) {
- array_append(EVAL_STACK, v1);
array_append(EVAL_STACK, v2);
for (int i = 0; i < v2->quote->size; i++) {
eval(value_copy(v2->quote->items[i]));
@@ -951,6 +951,7 @@ void compose(value_t *v) {
} else if (v2->type == VQUOTE && v1->type == VQUOTE) {
retval = v1;
array_extend(v1->quote, v2->quote);
+ free(v2->quote->items);
free(v2->quote);
free(v2);
} else {
@@ -1169,7 +1170,7 @@ void stemcut(value_t *v) {
for (int i = v1->int_float; i < v2->quote->size; i++) {
array_append(r2->quote, v2->quote->items[i]);
}
- // [ a b c ] 1 cut => [ a ] [ b c ]
+ /* [ a b c ] 1 cut => [ a ] [ b c ] */
break;
default:
array_append(STACK, v2);