summaryrefslogtreecommitdiff
path: root/runtime/extern.c
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/extern.c')
-rw-r--r--runtime/extern.c18
1 files changed, 10 insertions, 8 deletions
diff --git a/runtime/extern.c b/runtime/extern.c
index fe5aace607..ad3d552f54 100644
--- a/runtime/extern.c
+++ b/runtime/extern.c
@@ -158,12 +158,13 @@ static void free_extern_output(void)
{
struct output_block * blk, * nextblk;
- if (extern_userprovided_output != NULL) return;
- for (blk = extern_output_first; blk != NULL; blk = nextblk) {
- nextblk = blk->next;
- caml_stat_free(blk);
+ if (extern_userprovided_output == NULL) {
+ for (blk = extern_output_first; blk != NULL; blk = nextblk) {
+ nextblk = blk->next;
+ caml_stat_free(blk);
+ }
+ extern_output_first = NULL;
}
- extern_output_first = NULL;
extern_free_stack();
}
@@ -735,7 +736,7 @@ CAMLexport void caml_output_value_to_malloc(value v, value flags,
int header_len;
intnat data_len;
char * res;
- struct output_block * blk;
+ struct output_block * blk, * nextblk;
init_extern_output();
data_len = extern_value(v, flags, header, &header_len);
@@ -745,12 +746,13 @@ CAMLexport void caml_output_value_to_malloc(value v, value flags,
*len = header_len + data_len;
memcpy(res, header, header_len);
res += header_len;
- for (blk = extern_output_first; blk != NULL; blk = blk->next) {
+ for (blk = extern_output_first; blk != NULL; blk = nextblk) {
intnat n = blk->end - blk->data;
memcpy(res, blk->data, n);
res += n;
+ nextblk = blk->next;
+ caml_stat_free(blk);
}
- free_extern_output();
}
/* Functions for writing user-defined marshallers */