Permalink
Browse files

Fix 0 byte memory leak in zfs receive

Currently, when a DRR_OBJECT record is read into memory in
receive_read_record(), memory is allocated for the bonus buffer.
However, if the object doesnt have a bonus buffer the code will
still "allocate" the zero bytes, but the memory will not be passed
to the processing thread for cleanup later. This causes the spl
kmem trackking code to report a leak. This patch simply changes the
code so that it only allocates this memory if it has a non-zero
length.

Signed-off-by: Tom Caputi <tcaputi@datto.com>
  • Loading branch information...
tcaputi committed Jan 11, 2019
1 parent 8bd2a28 commit cfd1a6c7bfc2e328efc1ffeabcf9ee6c5d7776ec
Showing with 6 additions and 1 deletion.
  1. +6 −1 module/zfs/dmu_recv.c
@@ -1777,6 +1777,8 @@ receive_read_payload_and_next_header(struct receive_arg *ra, int len, void *buf)
ra->rrd->payload_size = len;
ra->rrd->bytes_read = ra->bytes_read;
}
} else {
ASSERT3U(buf, ==, NULL);
}

ra->prev_cksum = ra->cksum;
@@ -1928,9 +1930,12 @@ receive_read_record(struct receive_arg *ra)
{
struct drr_object *drro = &ra->rrd->header.drr_u.drr_object;
uint32_t size = DRR_OBJECT_PAYLOAD_SIZE(drro);
void *buf = kmem_zalloc(size, KM_SLEEP);
void *buf = NULL;
dmu_object_info_t doi;

if (size != 0)
buf = kmem_zalloc(size, KM_SLEEP);

err = receive_read_payload_and_next_header(ra, size, buf);
if (err != 0) {
kmem_free(buf, size);

0 comments on commit cfd1a6c

Please sign in to comment.