From eaaed26ffb3a14c0c98ce1e6e039e62327ab4447 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 767b341a4..6e0057bb9 100644 --- a/module/zfs/dmu_send.c +++ b/module/zfs/dmu_send.c @@ -2714,6 +2714,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); } @@ -2922,6 +2926,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 {