alloc_area() vfrees ps->zero_area and ps->area on allocation failure
but leaves the dangling pointers.  When the snapshot constructor then
calls free_area() as part of teardown, it vfrees the same buffers
again, triggering a WARNING in vfree().

Set those pointers to NULL after vfree().  vfree(NULL) is a no-op,
so free_area() is safe to call multiple times.

Reported-by: [email protected]
Fixes: 7c9e6c17325f ("dm exception store: refactor zero_area")
Signed-off-by: Shuai Liu <[email protected]>
---
 drivers/md/dm-snap-persistent.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/drivers/md/dm-snap-persistent.c b/drivers/md/dm-snap-persistent.c
index b587ee7330562..9f5ade4f51cec 100644
--- a/drivers/md/dm-snap-persistent.c
+++ b/drivers/md/dm-snap-persistent.c
@@ -194,9 +194,11 @@ static int alloc_area(struct pstore *ps)
 
 err_header_area:
        vfree(ps->zero_area);
+       ps->zero_area = NULL;
 
 err_zero_area:
        vfree(ps->area);
+       ps->area = NULL;
 
 err_area:
        return r;
-- 
2.43.0


Reply via email to