summaryrefslogtreecommitdiffstats
path: root/cddl
diff options
context:
space:
mode:
authormav <mav@FreeBSD.org>2015-11-13 09:46:28 +0000
committermav <mav@FreeBSD.org>2015-11-13 09:46:28 +0000
commitb470ddeee26e2e43483e1937c01e04874b5431b4 (patch)
tree81ff90b60b55155cc2a9406ca02d3e9b535bfc34 /cddl
parentac5dc15cb66baa14d39146d2869a47a0f5a83221 (diff)
downloadFreeBSD-src-b470ddeee26e2e43483e1937c01e04874b5431b4.zip
FreeBSD-src-b470ddeee26e2e43483e1937c01e04874b5431b4.tar.gz
MFC r289528: Reduce diff from upstream.
Should be no functional change.
Diffstat (limited to 'cddl')
-rw-r--r--cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c26
1 files changed, 13 insertions, 13 deletions
diff --git a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c
index a8803ca..1f868d3 100644
--- a/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c
+++ b/cddl/contrib/opensolaris/lib/libzfs/common/libzfs_pool.c
@@ -3729,17 +3729,18 @@ zpool_history_unpack(char *buf, uint64_t bytes_read, uint64_t *leftover,
int
zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
{
- char *buf = NULL;
- uint64_t bufsize = HIS_BUF_LEN_DEF;
+ char *buf;
+ uint64_t buflen = HIS_BUF_LEN_DEF;
uint64_t off = 0;
nvlist_t **records = NULL;
uint_t numrecords = 0;
int err, i;
- if ((buf = malloc(bufsize)) == NULL)
+ buf = malloc(buflen);
+ if (buf == NULL)
return (ENOMEM);
do {
- uint64_t bytes_read = bufsize;
+ uint64_t bytes_read = buflen;
uint64_t leftover;
if ((err = get_history(zhp, buf, &off, &bytes_read)) != 0)
@@ -3753,18 +3754,16 @@ zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
&leftover, &records, &numrecords)) != 0)
break;
off -= leftover;
-
- /*
- * If the history block is too big, double the buffer
- * size and try again.
- */
if (leftover == bytes_read) {
+ /*
+ * no progress made, because buffer is not big enough
+ * to hold this record; resize and retry.
+ */
+ buflen *= 2;
free(buf);
buf = NULL;
-
- bufsize <<= 1;
- if ((bufsize >= HIS_BUF_LEN_MAX) ||
- ((buf = malloc(bufsize)) == NULL)) {
+ if ((buflen >= HIS_BUF_LEN_MAX) ||
+ ((buf = malloc(buflen)) == NULL)) {
err = ENOMEM;
break;
}
@@ -3772,6 +3771,7 @@ zpool_get_history(zpool_handle_t *zhp, nvlist_t **nvhisp)
/* CONSTCOND */
} while (1);
+
free(buf);
if (!err) {
OpenPOWER on IntegriCloud