From 0d329c657982a5002c766cb48c4e80bd76e9f231 Mon Sep 17 00:00:00 2001 From: Richard Yao Date: Thu, 29 Sep 2022 22:31:57 -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. Signed-off-by: Richard Yao --- 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 4ee3ffc352b8..dc415fa65c79 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 {