From 849797a3986b1175a2695b7565dc52ce7cedcb36 Mon Sep 17 00:00:00 2001 From: JacobBarthelmeh Date: Thu, 27 Aug 2020 14:33:23 -0700 Subject: [PATCH] handle dangling directory opens --- src/wolfsftp.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/src/wolfsftp.c b/src/wolfsftp.c index 67bbebd..e9175c5 100644 --- a/src/wolfsftp.c +++ b/src/wolfsftp.c @@ -8040,6 +8040,29 @@ int wolfSSH_SFTP_free(WOLFSSH* ssh) } } #endif + +#ifndef NO_WOLFSSH_DIR + { + /* free all dirs if hung up on */ + DIR_HANDLE* cur = dirList; + + /* find DIR given handle */ + while (cur != NULL) { + DIR_HANDLE* toFree = cur; + + cur = cur->next; + #ifdef USE_WINDOWS_API + FindClose(toFree->dir); + #else + WCLOSEDIR(&toFree->dir); + #endif + if (toFree->dirName != NULL) + WFREE(toFree->dirName, ssh->ctx->heap, DYNTYPE_SFTP); + WFREE(toFree, ssh->ctx->heap, DYNTYPE_SFTP); + } + } +#endif /* NO_WOLFSSH_DIR */ + wolfSSH_SFTP_ClearState(ssh, STATE_ID_ALL); return WS_SUCCESS; }