Skip to content

Commit 667b0f9

Browse files
committed
libnilfsgc: fix potential memory or mmap leak in nilfs_acc_blocks()
If nilfs_acc_blocks_segment() fails, nilfs_acc_blocks() returns an error without releasing the segment allocated by nilfs_get_segment() with nilfs_put_segment(). Fix this potential leak issue by calling nilfs_put_segment() regardless of whether the call to nilfs_acc_blocks_segment() is successful or not. Signed-off-by: Ryusuke Konishi <konishi.ryusuke@gmail.com>
1 parent 4b982f8 commit 667b0f9

File tree

1 file changed

+1
-5
lines changed

1 file changed

+1
-5
lines changed

lib/gc.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -309,11 +309,7 @@ static ssize_t nilfs_acc_blocks(struct nilfs *nilfs,
309309
}
310310
ret = nilfs_acc_blocks_segment(&segment, si.sui_nblocks,
311311
vdescv, bdescv);
312-
if (unlikely(ret < 0))
313-
return -1;
314-
315-
ret = nilfs_put_segment(&segment);
316-
if (unlikely(ret < 0))
312+
if (unlikely(nilfs_put_segment(&segment) < 0 || ret < 0))
317313
return -1;
318314
i++;
319315
}

0 commit comments

Comments
 (0)