- if (!buffer->data) {
- buffer->data = zmalloc(rounded_capacity);
- if (!buffer->data) {
- ret = -1;
- goto end;
- }
- } else {
- void *new_buf;
-
- new_buf = realloc(buffer->data, rounded_capacity);
- if (new_buf) {
- if (rounded_capacity > buffer->capacity) {
- memset(new_buf + buffer->capacity, 0,
- rounded_capacity - buffer->capacity);
- }
- } else {
- /* Realloc failed, try to acquire a new block. */
- new_buf = zmalloc(rounded_capacity);
- if (!new_buf) {
- ret = -1;
- goto end;
- }
- memcpy(new_buf, buffer->data, buffer->size);
- free(buffer->data);
- }
- buffer->data = new_buf;
+ /* Memory is initialized by the size increases. */
+ new_buf = realloc(buffer->data, new_capacity);
+ if (!new_buf) {
+ ret = -1;
+ goto end;