Skip to content

Commit 9d01f6f

Browse files
dhavalehsiangkao
authored andcommitted
erofs: fix possible memory leak in z_erofs_gbuf_exit()
Because we incorrectly reused of variable `i` in `z_erofs_gbuf_exit()` for inner loop, we may exit early from outer loop resulting in memory leak. Fix this by using separate variable for iterating through inner loop. Fixes: f36f301 ("erofs: rename per-CPU buffers to global buffer pool and make it configurable") Signed-off-by: Sandeep Dhavale <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Chao Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent f266106 commit 9d01f6f

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

fs/erofs/zutil.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ int __init z_erofs_gbuf_init(void)
148148

149149
void z_erofs_gbuf_exit(void)
150150
{
151-
int i;
151+
int i, j;
152152

153153
for (i = 0; i < z_erofs_gbuf_count + (!!z_erofs_rsvbuf); ++i) {
154154
struct z_erofs_gbuf *gbuf = &z_erofs_gbufpool[i];
@@ -161,9 +161,9 @@ void z_erofs_gbuf_exit(void)
161161
if (!gbuf->pages)
162162
continue;
163163

164-
for (i = 0; i < gbuf->nrpages; ++i)
165-
if (gbuf->pages[i])
166-
put_page(gbuf->pages[i]);
164+
for (j = 0; j < gbuf->nrpages; ++j)
165+
if (gbuf->pages[j])
166+
put_page(gbuf->pages[j]);
167167
kfree(gbuf->pages);
168168
gbuf->pages = NULL;
169169
}

0 commit comments

Comments
 (0)