From: guoju fang <fangguoju@gmail.com>
To: colyli@suse.de
Cc: kent.overstreet@gmail.com, linux-bcache@vger.kernel.org,
linux-block@vger.kernel.org
Subject: Re: [PATCH] bcache: fix memleak when error occurred before journal replay
Date: Tue, 30 Apr 2019 09:38:35 +0800 [thread overview]
Message-ID: <cae10f04-9a2c-db48-97ad-0cdd7e88a0b8@gmail.com> (raw)
In-Reply-To: <1556541059-21234-1-git-send-email-fangguoju@gmail.com>
Oh, Shenghui submitted a patch to fix this bug days ago, so please
ignore this.
On 2019/4/29 20:30, Guoju Fang wrote:
> A list of struct journal_replay is allocated when register cache device
> and will be freed when journal replay complete. It will cause memory
> leaks if some error occurred before journal replay.
>
> Signed-off-by: Guoju Fang <fangguoju@gmail.com>
> ---
> drivers/md/bcache/super.c | 20 ++++++++++++++------
> 1 file changed, 14 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/md/bcache/super.c b/drivers/md/bcache/super.c
> index a697a3a..e4289291 100644
> --- a/drivers/md/bcache/super.c
> +++ b/drivers/md/bcache/super.c
> @@ -1782,6 +1782,7 @@ static void run_cache_set(struct cache_set *c)
> struct cache *ca;
> struct closure cl;
> unsigned int i;
> + LIST_HEAD(journal);
>
> closure_init_stack(&cl);
>
> @@ -1790,7 +1791,6 @@ static void run_cache_set(struct cache_set *c)
> set_gc_sectors(c);
>
> if (CACHE_SYNC(&c->sb)) {
> - LIST_HEAD(journal);
> struct bkey *k;
> struct jset *j;
>
> @@ -1820,25 +1820,25 @@ static void run_cache_set(struct cache_set *c)
>
> err = "bad btree root";
> if (__bch_btree_ptr_invalid(c, k))
> - goto err;
> + goto free_journal;
>
> err = "error reading btree root";
> c->root = bch_btree_node_get(c, NULL, k,
> j->btree_level,
> true, NULL);
> if (IS_ERR_OR_NULL(c->root))
> - goto err;
> + goto free_journal;
>
> list_del_init(&c->root->list);
> rw_unlock(true, c->root);
>
> err = uuid_read(c, j, &cl);
> if (err)
> - goto err;
> + goto free_journal;
>
> err = "error in recovery";
> if (bch_btree_check(c))
> - goto err;
> + goto free_journal;
>
> bch_journal_mark(c, &journal);
> bch_initial_gc_finish(c);
> @@ -1854,7 +1854,7 @@ static void run_cache_set(struct cache_set *c)
> err = "error starting allocator thread";
> for_each_cache(ca, c, i)
> if (bch_cache_allocator_start(ca))
> - goto err;
> + goto free_journal;
>
> /*
> * First place it's safe to allocate: btree_check() and
> @@ -1938,6 +1938,14 @@ static void run_cache_set(struct cache_set *c)
>
> set_bit(CACHE_SET_RUNNING, &c->flags);
> return;
> +
> +free_journal:
> + while (!list_empty(&journal)) {
> + struct journal_replay *jr = list_first_entry(&journal,
> + struct journal_replay, list);
> + list_del(&jr->list);
> + kfree(jr);
> + }
> err:
> closure_sync(&cl);
> /* XXX: test this, it's broken */
prev parent reply other threads:[~2019-04-30 1:38 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-04-29 12:30 [PATCH] bcache: fix memleak when error occurred before journal replay Guoju Fang
2019-04-30 1:38 ` guoju fang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cae10f04-9a2c-db48-97ad-0cdd7e88a0b8@gmail.com \
--to=fangguoju@gmail.com \
--cc=colyli@suse.de \
--cc=kent.overstreet@gmail.com \
--cc=linux-bcache@vger.kernel.org \
--cc=linux-block@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).