summaryrefslogtreecommitdiffhomepage
path: root/src/dump.c
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2013-03-28 06:50:40 -0700
committerYukihiro "Matz" Matsumoto <[email protected]>2013-03-28 06:50:40 -0700
commit326aa3f98eb3b429726396617d161dd1ec5ad792 (patch)
tree0db20ce284ab0682b040546e7150eed676b07642 /src/dump.c
parenta6cca7c2c41ead0d3eb9afc838d7033465c52764 (diff)
parent31bb00b9c2d84e1e2c7efe64675f78ac99c3a399 (diff)
downloadmruby-326aa3f98eb3b429726396617d161dd1ec5ad792.tar.gz
mruby-326aa3f98eb3b429726396617d161dd1ec5ad792.zip
Merge pull request #1095 from monaka/pr-add-arena-guard
Add arena guard. It will be exausted when the pool is huge.
Diffstat (limited to 'src/dump.c')
-rw-r--r--src/dump.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/src/dump.c b/src/dump.c
index d3f6ee62b..f4c48d951 100644
--- a/src/dump.c
+++ b/src/dump.c
@@ -76,6 +76,8 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep)
size += irep->plen * (sizeof(uint8_t) + sizeof(uint16_t)); /* len(n) */
for (pool_no = 0; pool_no < irep->plen; pool_no++) {
+ int ai = mrb_gc_arena_save(mrb);
+
switch (mrb_type(irep->pool[pool_no])) {
case MRB_TT_FIXNUM:
str = mrb_fix2str(mrb, irep->pool[pool_no], 10);
@@ -95,6 +97,8 @@ get_pool_block_size(mrb_state *mrb, mrb_irep *irep)
default:
break;
}
+
+ mrb_gc_arena_restore(mrb, ai);
}
return size;
@@ -120,6 +124,8 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf)
cur += uint32_to_bin(irep->plen, cur); /* number of pool */
for (pool_no = 0; pool_no < irep->plen; pool_no++) {
+ int ai = mrb_gc_arena_save(mrb);
+
cur += uint8_to_bin(mrb_type(irep->pool[pool_no]), cur); /* data type */
memset(char_buf, 0, buf_size);
@@ -141,6 +147,7 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf)
buf_size = len + 1;
char_buf = (char *)mrb_realloc(mrb, char_buf, buf_size);
if (char_buf == NULL) {
+ mrb_gc_arena_restore(mrb, ai);
result = MRB_DUMP_GENERAL_FAILURE;
goto error_exit;
}
@@ -157,6 +164,8 @@ write_pool_block(mrb_state *mrb, mrb_irep *irep, uint8_t *buf)
cur += uint16_to_bin(len, cur); /* data length */
memcpy(cur, char_buf, len);
cur += len;
+
+ mrb_gc_arena_restore(mrb, ai);
}
result = (int)(cur - buf);