Skip to content

Commit

Permalink
Free given pointer if realloc() fails; fix #3658
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed May 25, 2017
1 parent ff46957 commit 4566c80
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/state.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,13 @@ mrb_open_core(mrb_allocf f, void *ud)
void*
mrb_default_allocf(mrb_state *mrb, void *p, size_t size, void *ud)
{
if (size == 0) {
void *p2;

if (size == 0 || (p2 = realloc(p, size)) == NULL) {
free(p);
return NULL;
}
else {
return realloc(p, size);
}
return p2;
}

struct alloca_header {
Expand Down

0 comments on commit 4566c80

Please sign in to comment.