Skip to content
Permalink
Browse files
Free given pointer if realloc() fails; fix #3658
  • Loading branch information
matz committed May 25, 2017
1 parent ff46957 commit 4566c80d7b8b9b9117128f6b11f7420aae530a86
Showing 1 changed file with 4 additions and 4 deletions.
@@ -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 {

0 comments on commit 4566c80

Please sign in to comment.