Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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.
- Loading branch information
9cdf439
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this change mean that if the string object fails to expand, for example, the string object will continue to hold an invalid pointer, leading to a double free?
I think it's better to have a separate function that does this commit behavior.
How about
mrb_reallocf()
?This name comes from FreeBSD's own
reallocf()
, which seems to be available on Solaris and illumos recently.9cdf439
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indeed. I will stop freeing inside of
realloc
.