Skip to content

Commit f639d98

Browse files
lxbszidryomov
authored andcommitted
ceph: fix memory leak in ceph_readdir when note_last_dentry returns error
Reset the last_readdir at the same time, and add a comment explaining why we don't free last_readdir when dir_emit returns false. Signed-off-by: Xiubo Li <xiubli@redhat.com> Reviewed-by: Jeff Layton <jlayton@kernel.org> Signed-off-by: Ilya Dryomov <idryomov@gmail.com>
1 parent c38af98 commit f639d98

1 file changed

Lines changed: 10 additions & 1 deletion

File tree

fs/ceph/dir.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,11 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
478478
2 : (fpos_off(rde->offset) + 1);
479479
err = note_last_dentry(dfi, rde->name, rde->name_len,
480480
next_offset);
481-
if (err)
481+
if (err) {
482+
ceph_mdsc_put_request(dfi->last_readdir);
483+
dfi->last_readdir = NULL;
482484
return err;
485+
}
483486
} else if (req->r_reply_info.dir_end) {
484487
dfi->next_offset = 2;
485488
/* keep last name */
@@ -520,6 +523,12 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
520523
if (!dir_emit(ctx, rde->name, rde->name_len,
521524
ceph_present_ino(inode->i_sb, le64_to_cpu(rde->inode.in->ino)),
522525
le32_to_cpu(rde->inode.in->mode) >> 12)) {
526+
/*
527+
* NOTE: Here no need to put the 'dfi->last_readdir',
528+
* because when dir_emit stops us it's most likely
529+
* doesn't have enough memory, etc. So for next readdir
530+
* it will continue.
531+
*/
523532
dout("filldir stopping us...\n");
524533
return 0;
525534
}

0 commit comments

Comments
 (0)