diff --git a/include/libwebsockets/lws-vfs.h b/include/libwebsockets/lws-vfs.h index 040ddc04e..b10d2d628 100644 --- a/include/libwebsockets/lws-vfs.h +++ b/include/libwebsockets/lws-vfs.h @@ -202,7 +202,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 65450cf08..b3d8ad513 100644 --- a/lib/core-net/close.c +++ b/lib/core-net/close.c @@ -408,6 +408,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_SYS_ASYNC_DNS) lws_async_dns_cancel(wsi); #endif diff --git a/lib/roles/http/client/client-handshake.c b/lib/roles/http/client/client-handshake.c index 056b3010b..8a29e6899 100644 --- a/lib/roles/http/client/client-handshake.c +++ b/lib/roles/http/client/client-handshake.c @@ -333,6 +333,7 @@ lws_client_connect_3_connect(struct lws *wsi, const char *ads, #if defined(LWS_WITH_UNIX_SOCK) if (ads && *ads == '+') { ads++; + memset(&sa46, 0, sizeof(sa46)); memset(&sau, 0, sizeof(sau)); sau.sun_family = AF_UNIX; strncpy(sau.sun_path, ads, sizeof(sau.sun_path)); diff --git a/lib/roles/http/server/server.c b/lib/roles/http/server/server.c index fa2c408da..b54fb2138 100644 --- a/lib/roles/http/server/server.c +++ b/lib/roles/http/server/server.c @@ -2253,6 +2253,11 @@ lws_http_transaction_completed(struct lws *wsi) #ifdef LWS_WITH_ACCESS_LOG 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;