- if (*size == max)
- buffer = talloc_realloc(ctx, buffer, char, max*=2 + 1);
+ if (*size == max) {
+ buffer = talloc_realloc(ctx, buffer, char, max*2+1);
+ if (!buffer) {
+ buffer = talloc_realloc(ctx, buffer, char,
+ max + 1024*1024 + 1);
+ if (!buffer)
+ return NULL;
+ max += 1024*1024;
+ } else
+ max *= 2;
+ }