mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
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.
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user