diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-06-23 13:19:10 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2020-06-25 06:57:43 +0900 |
| commit | 9cdf439db52b66447b4e37c61179d54fad6c8f33 (patch) | |
| tree | c89e9163d96b5ce6478bf054c02f19c0b407fc9d /src/gc.c | |
| parent | 95360a17f2260a46daeab2ed3456cd7c25c162ef (diff) | |
| download | mruby-9cdf439db52b66447b4e37c61179d54fad6c8f33.tar.gz mruby-9cdf439db52b66447b4e37c61179d54fad6c8f33.zip | |
Free the original pointer if `realloc` failed.
The POSIX `realloc` keep the original pointer untouched, so it can
easily leads to memory leakage. `mrb_realloc()` should handle those
bookkeeping, while `mrb_realloc_simple()` keeps the original `realloc`
behavior.
Diffstat (limited to 'src/gc.c')
| -rw-r--r-- | src/gc.c | 11 |
1 files changed, 3 insertions, 8 deletions
@@ -225,14 +225,9 @@ mrb_realloc(mrb_state *mrb, void *p, size_t len) p2 = mrb_realloc_simple(mrb, p, len); if (len == 0) return p2; if (p2 == NULL) { - if (mrb->gc.out_of_memory) { - mrb_raise_nomemory(mrb); - /* mrb_panic(mrb); */ - } - else { - mrb->gc.out_of_memory = TRUE; - mrb_raise_nomemory(mrb); - } + mrb_free(mrb, p); + mrb->gc.out_of_memory = TRUE; + mrb_raise_nomemory(mrb); } else { mrb->gc.out_of_memory = FALSE; |
