From 0ea03c7c8273c2a1a48b86c397c727c076c86a06 Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Sat, 18 Jan 2020 21:40:30 +0100 Subject: [PATCH] dmu_send: redacted: fix memory leak on invalid redaction/from bookmark Reviewed-by: Brian Behlendorf Reviewed-by: Matt Ahrens Signed-off-by: Christian Schwarz Closes #9867 --- module/zfs/dmu_send.c | 12 ++++++------ .../functional/redacted_send/redacted_negative.ksh | 4 ++++ 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/module/zfs/dmu_send.c b/module/zfs/dmu_send.c index 62de978d3..469959302 100644 --- a/module/zfs/dmu_send.c +++ b/module/zfs/dmu_send.c @@ -2342,12 +2342,6 @@ dmu_send_impl(struct dmu_send_params *dspp) return (err); } - from_arg = kmem_zalloc(sizeof (*from_arg), KM_SLEEP); - to_arg = kmem_zalloc(sizeof (*to_arg), KM_SLEEP); - rlt_arg = kmem_zalloc(sizeof (*rlt_arg), KM_SLEEP); - smt_arg = kmem_zalloc(sizeof (*smt_arg), KM_SLEEP); - spt_arg = kmem_zalloc(sizeof (*spt_arg), KM_SLEEP); - /* * If we're doing a redacted send, hold the bookmark's redaction list. */ @@ -2382,6 +2376,12 @@ dmu_send_impl(struct dmu_send_params *dspp) dsl_dataset_long_hold(to_ds, FTAG); + from_arg = kmem_zalloc(sizeof (*from_arg), KM_SLEEP); + to_arg = kmem_zalloc(sizeof (*to_arg), KM_SLEEP); + rlt_arg = kmem_zalloc(sizeof (*rlt_arg), KM_SLEEP); + smt_arg = kmem_zalloc(sizeof (*smt_arg), KM_SLEEP); + spt_arg = kmem_zalloc(sizeof (*spt_arg), KM_SLEEP); + drr = create_begin_record(dspp, os, featureflags); dssp = setup_send_progress(dspp); diff --git a/tests/zfs-tests/tests/functional/redacted_send/redacted_negative.ksh b/tests/zfs-tests/tests/functional/redacted_send/redacted_negative.ksh index 8eafc4706..5ea65e3e7 100755 --- a/tests/zfs-tests/tests/functional/redacted_send/redacted_negative.ksh +++ b/tests/zfs-tests/tests/functional/redacted_send/redacted_negative.ksh @@ -77,6 +77,10 @@ log_mustnot zfs redact $recvfs@snap book5 $clone3@snap # Nor may a redacted dataset appear in the redaction list. log_mustnot zfs redact testpool2/recvfs@snap2 book7 testpool2/recvfs@snap +# Non-redaction bookmark cannot be sent and produces invalid argument error +log_must zfs bookmark "$sendfs@snap1" "$sendfs#book8" +log_must eval "zfs send --redact book8 -i $sendfs@snap1 $sendfs@snap2 2>&1 | head -n 100 | grep 'internal error: Invalid argument'" + # Error messages for common usage errors log_mustnot_expect "not contain '#'" zfs redact $sendfs@snap1 \#book $sendfs@snap2 log_mustnot_expect "not contain '#'" zfs redact $sendfs@snap1 $sendfs#book $sendfs@snap2