diff options
Diffstat (limited to 'src/bin/pg_basebackup/walmethods.c')
-rw-r--r-- | src/bin/pg_basebackup/walmethods.c | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/src/bin/pg_basebackup/walmethods.c b/src/bin/pg_basebackup/walmethods.c index 870b6d085e8..2953ba463dd 100644 --- a/src/bin/pg_basebackup/walmethods.c +++ b/src/bin/pg_basebackup/walmethods.c @@ -115,18 +115,17 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ /* Do pre-padding on non-compressed files */ if (pad_to_size && dir_data->compression == 0) { - char *zerobuf; + PGAlignedXLogBlock zerobuf; int bytes; - zerobuf = pg_malloc0(XLOG_BLCKSZ); + memset(zerobuf.data, 0, XLOG_BLCKSZ); for (bytes = 0; bytes < pad_to_size; bytes += XLOG_BLCKSZ) { errno = 0; - if (write(fd, zerobuf, XLOG_BLCKSZ) != XLOG_BLCKSZ) + if (write(fd, zerobuf.data, XLOG_BLCKSZ) != XLOG_BLCKSZ) { int save_errno = errno; - pg_free(zerobuf); close(fd); /* @@ -136,7 +135,6 @@ dir_open_for_write(const char *pathname, const char *temp_suffix, size_t pad_to_ return NULL; } } - pg_free(zerobuf); if (lseek(fd, 0, SEEK_SET) != 0) { @@ -512,24 +510,20 @@ tar_write(Walfile f, const void *buf, size_t count) static bool tar_write_padding_data(TarMethodFile *f, size_t bytes) { - char *zerobuf = pg_malloc0(XLOG_BLCKSZ); + PGAlignedXLogBlock zerobuf; size_t bytesleft = bytes; + memset(zerobuf.data, 0, XLOG_BLCKSZ); while (bytesleft) { - size_t bytestowrite = bytesleft > XLOG_BLCKSZ ? XLOG_BLCKSZ : bytesleft; - - ssize_t r = tar_write(f, zerobuf, bytestowrite); + size_t bytestowrite = Min(bytesleft, XLOG_BLCKSZ); + ssize_t r = tar_write(f, zerobuf.data, bytestowrite); if (r < 0) - { - pg_free(zerobuf); return false; - } bytesleft -= r; } - pg_free(zerobuf); return true; } |