From f04d18b5da63e4b48d91a1617979aabf89f2933e Mon Sep 17 00:00:00 2001 From: Andy Green Date: Sat, 16 Nov 2019 08:20:48 +0000 Subject: [PATCH] server vfs: close: cleanup also at just_kill_connection ... and at transaction completion --- include/libwebsockets/lws-vfs.h | 5 ++++- lib/core-net/close.c | 6 ++++++ lib/roles/http/server/server.c | 6 ++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/libwebsockets/lws-vfs.h b/include/libwebsockets/lws-vfs.h index 00e2fda5d..1586fecd4 100644 --- a/include/libwebsockets/lws-vfs.h +++ b/include/libwebsockets/lws-vfs.h @@ -201,7 +201,10 @@ lws_vfs_file_open(const struct lws_plat_file_ops *fops, const char *vfs_path, static LWS_INLINE int lws_vfs_file_close(lws_fop_fd_t *fop_fd) { - return (*fop_fd)->fops->LWS_FOP_CLOSE(fop_fd); + if (*fop_fd && (*fop_fd)->fops) + return (*fop_fd)->fops->LWS_FOP_CLOSE(fop_fd); + + return 0; } /** diff --git a/lib/core-net/close.c b/lib/core-net/close.c index f561e94e7..4162702d2 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -345,6 +345,12 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason, just_kill_connection: +#if defined(LWS_WITH_FILE_OPS) && (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) + if (lwsi_role_http(wsi) && lwsi_role_server(wsi) && + wsi->http.fop_fd != NULL) + lws_vfs_file_close(&wsi->http.fop_fd); +#endif + #if defined(LWS_WITH_HTTP_PROXY) if (wsi->http.buflist_post_body) lws_buflist_destroy_all_segments(&wsi->http.buflist_post_body); diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index 763d8b812..6bec745cb 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -2224,6 +2224,12 @@ lws_http_transaction_completed(struct lws *wsi) wsi->http.access_log.sent = 0; #endif +#if defined(LWS_WITH_FILE_OPS) && (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) + if (lwsi_role_http(wsi) && lwsi_role_server(wsi) && + wsi->http.fop_fd != NULL) + lws_vfs_file_close(&wsi->http.fop_fd); +#endif + if (wsi->vhost->keepalive_timeout) n = PENDING_TIMEOUT_HTTP_KEEPALIVE_IDLE; lws_set_timeout(wsi, n, wsi->vhost->keepalive_timeout);