2 parents bde25e9 + 35b6828 commit 027e54bCopy full SHA for 027e54b
1 file changed
lib/erl_interface/src/misc/ei_x_encode.c
@@ -69,9 +69,13 @@ int x_fix_buff(ei_x_buff* x, int szneeded)
69
{
70
int sz = szneeded + ei_x_extra;
71
if (sz > x->buffsz) {
72
- sz += ei_x_extra; /* to avoid reallocating each and every time */
73
- x->buffsz = sz;
74
- x->buff = ei_realloc(x->buff, sz);
+ char* newbuff;
+ sz += ei_x_extra; /* to avoid reallocating each and every time */
+ newbuff = ei_realloc(x->buff, sz);
75
+ if (newbuff == NULL)
76
+ return 0; /* leave x->buff and x->buffsz intact on failure */
77
+ x->buff = newbuff;
78
+ x->buffsz = sz;
79
}
80
return x->buff != NULL;
81
0 commit comments