From 3830858c5cb4d209b1a05e6a3dde6b77cb88f2b3 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Tue, 18 Oct 2022 19:03:33 -0400 Subject: [PATCH] Fix memory leaks in dmu_send()/dmu_send_obj() If we encounter an EXDEV error when using the redacted snapshots feature, the memory used by dspp.fromredactsnaps is leaked. Clang's static analyzer caught this during an experiment in which I had annotated various headers in an attempt to improve the results of static analysis. Reviewed-by: Brian Behlendorf Signed-off-by: Richard Yao Closes #13973 --- module/zfs/dmu_send.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/module/zfs/dmu_send.c b/module/zfs/dmu_send.c index 390afba926..20ec4ac173 100644 --- a/module/zfs/dmu_send.c +++ b/module/zfs/dmu_send.c @@ -2716,6 +2716,10 @@ dmu_send_obj(const char *pool, uint64_t tosnap, uint64_t fromsnap, dspp.numfromredactsnaps = NUM_SNAPS_NOT_REDACTED; err = dmu_send_impl(&dspp); } + if (dspp.fromredactsnaps) + kmem_free(dspp.fromredactsnaps, + dspp.numfromredactsnaps * sizeof (uint64_t)); + dsl_dataset_rele(dspp.to_ds, FTAG); return (err); } @@ -2924,6 +2928,10 @@ dmu_send(const char *tosnap, const char *fromsnap, boolean_t embedok, /* dmu_send_impl will call dsl_pool_rele for us. */ err = dmu_send_impl(&dspp); } else { + if (dspp.fromredactsnaps) + kmem_free(dspp.fromredactsnaps, + dspp.numfromredactsnaps * + sizeof (uint64_t)); dsl_pool_rele(dspp.dp, FTAG); } } else {