Skip to content

Commit d6cda56

Browse files
committed
Fix memory leak: copy bind_address_storage to webserver
The webserver was only copying the raw bind_address pointer but not the shared_ptr that owns the storage. This caused the memory to be freed when the temporary create_webserver was destroyed, leaving webserver with a dangling pointer and causing valgrind to report a leak.
1 parent e0a47e3 commit d6cda56

File tree

2 files changed

+2
-0
lines changed

2 files changed

+2
-0
lines changed

src/httpserver/webserver.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,7 @@ class webserver {
144144
validator_ptr validator;
145145
unescaper_ptr unescaper;
146146
const struct sockaddr* bind_address;
147+
std::shared_ptr<struct sockaddr_storage> bind_address_storage;
147148
/* Changed type to MHD_socket because this type will always reflect the
148149
platform's actual socket type (e.g. SOCKET on windows, int on unixes)*/
149150
MHD_socket bind_socket;

src/webserver.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ webserver::webserver(const create_webserver& params):
134134
validator(params._validator),
135135
unescaper(params._unescaper),
136136
bind_address(params._bind_address),
137+
bind_address_storage(params._bind_address_storage),
137138
bind_socket(params._bind_socket),
138139
max_thread_stack_size(params._max_thread_stack_size),
139140
use_ssl(params._use_ssl),

0 commit comments

Comments
 (0)