Skip to content

Commit 9224070

Browse files
ryaoandrewc12
authored andcommitted
abd_return_buf() should call zfs_refcount_remove_many() early
Calling zfs_refcount_remove_many() after freeing memory means we pass a reference to freed memory as the holder. This is not believed to be able to cause a problem, but there is a bit of a tradition of fixing these issues when they appear so that they do not obscure more serious issues in static analyzer output, so we fix this one too. Clang's static analyzer found this with the help of CodeChecker's CTU analysis. Reviewed-by: Brian Behlendorf <[email protected]> Signed-off-by: Richard Yao <[email protected]> Closes openzfs#14043
1 parent 236f45f commit 9224070

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

module/zfs/abd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,15 +667,15 @@ abd_return_buf(abd_t *abd, void *buf, size_t n)
667667
{
668668
abd_verify(abd);
669669
ASSERT3U(abd->abd_size, >=, n);
670+
#ifdef ZFS_DEBUG
671+
(void) zfs_refcount_remove_many(&abd->abd_children, n, buf);
672+
#endif
670673
if (abd_is_linear(abd)) {
671674
ASSERT3P(buf, ==, abd_to_buf(abd));
672675
} else {
673676
ASSERT0(abd_cmp_buf(abd, buf, n));
674677
zio_buf_free(buf, n);
675678
}
676-
#ifdef ZFS_DEBUG
677-
(void) zfs_refcount_remove_many(&abd->abd_children, n, buf);
678-
#endif
679679
}
680680

681681
void

0 commit comments

Comments
 (0)