From: Volker Lendecke Date: Wed, 2 Feb 2022 07:58:15 +0000 (+0100) Subject: smbd: No base fsps to close_file_free() from file_close_user() X-Git-Tag: tevent-0.12.0~748 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1fbd9877fead466a17d697c143cd370c0b27f610;p=thirdparty%2Fsamba.git smbd: No base fsps to close_file_free() from file_close_user() Same logic as the change for file_close_conn() Signed-off-by: Volker Lendecke Reviewed-by: Jeremy Allison --- diff --git a/source3/smbd/files.c b/source3/smbd/files.c index da3f3dc29be..917f854aa7e 100644 --- a/source3/smbd/files.c +++ b/source3/smbd/files.c @@ -912,15 +912,40 @@ bool file_init(struct smbd_server_connection *sconn) Close files open by a specified vuid. ****************************************************************************/ +struct file_close_user_state { + uint64_t vuid; + bool fsp_left_behind; +}; + +static struct files_struct *file_close_user_fn( + struct files_struct *fsp, + void *private_data) +{ + struct file_close_user_state *state = private_data; + bool did_close; + + if (fsp->vuid != state->vuid) { + return NULL; + } + + did_close = close_file_in_loop(fsp); + if (!did_close) { + state->fsp_left_behind = true; + } + + return NULL; +} + void file_close_user(struct smbd_server_connection *sconn, uint64_t vuid) { - files_struct *fsp, *next; + struct file_close_user_state state = { .vuid = vuid }; - for (fsp=sconn->files; fsp; fsp=next) { - next=fsp->next; - if (fsp->vuid == vuid) { - close_file_free(NULL, &fsp, SHUTDOWN_CLOSE); - } + files_forall(sconn, file_close_user_fn, &state); + + if (state.fsp_left_behind) { + state.fsp_left_behind = false; + files_forall(sconn, file_close_user_fn, &state); + SMB_ASSERT(!state.fsp_left_behind); } }