From a7a17711ecd2a65a455cd7590debec1d166efb84 Mon Sep 17 00:00:00 2001
From: Sergey Lyubka <valenok@gmail.com>
Date: Mon, 10 Mar 2014 08:35:41 +0000
Subject: [PATCH] Resetting endpoint_type in open_local_endpoint()

---
 mongoose.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/mongoose.c b/mongoose.c
index e91574355..9fdfa305d 100644
--- a/mongoose.c
+++ b/mongoose.c
@@ -729,7 +729,8 @@ static void ns_write_to_socket(struct ns_connection *conn) {
   ns_hexdump(conn, io->buf, n, "->");
 #endif
 
-  DBG(("%p -> %d bytes [%.*s%s]", conn, n, io->len < 40 ? io->len : 40,
+  DBG(("%p -> %d bytes %d [%.*s%s]", conn, n, conn->flags,
+       io->len < 40 ? io->len : 40,
        io->buf, io->len < 40 ? "" : "..."));
 
   if (ns_is_error(n)) {
@@ -3925,7 +3926,7 @@ static void lsp(struct connection *conn, const char *p, int len, lua_State *L) {
 
 static void handle_lsp_request(struct connection *conn, const char *path,
                                file_stat_t *st) {
-  void *p = NULL;
+  void *p = MAP_FAILED;
   lua_State *L = NULL;
   FILE *fp = NULL;
 
@@ -3946,7 +3947,7 @@ static void handle_lsp_request(struct connection *conn, const char *path,
   }
 
   if (L != NULL) lua_close(L);
-  if (p != NULL) munmap(p, st->st_size);
+  if (p != MAP_FAILED) munmap(p, st->st_size);
   if (fp != NULL) fclose(fp);
 }
 #endif // MONGOOSE_USE_LUA
@@ -4125,6 +4126,9 @@ static void open_local_endpoint(struct connection *conn, int skip_user) {
 #endif
 #endif
 
+  // If EP_USER was set in a prev call, reset it
+  conn->endpoint_type = EP_NONE;
+
 #ifndef MONGOOSE_NO_AUTH
   if (conn->server->event_handler && call_user(conn, MG_AUTH) == MG_FALSE) {
     mg_send_digest_auth_request(&conn->mg_conn);
-- 
GitLab