From 433321ee8f163cb9555f7aa9ed5001d92ffde5c6 Mon Sep 17 00:00:00 2001 From: David Sterba Date: Tue, 11 Jan 2022 17:34:08 +0100 Subject: [PATCH] btrfs-progs: send: properly handle an ERR_PTR in find_good_parent Pointer returned from get_parent needs additional handling otherwise we could return an error and then try to free it. Reset the pointer when the error occurs so the cleanup is always done on a valid pointer. Issue: #423 Signed-off-by: David Sterba --- cmds/send.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmds/send.c b/cmds/send.c index 18102331..087af05c 100644 --- a/cmds/send.c +++ b/cmds/send.c @@ -108,6 +108,7 @@ static int find_good_parent(struct btrfs_send *sctx, u64 root_id, u64 *found) ret = -ENOENT; else ret = PTR_ERR(parent); + parent = NULL; goto out; } @@ -142,6 +143,7 @@ static int find_good_parent(struct btrfs_send *sctx, u64 root_id, u64 *found) ret = -ENOENT; else ret = PTR_ERR(parent2); + parent2 = NULL; goto out; } tmp = parent2->ctransid - parent->ctransid;