Fix a few memory leaks
This commit is contained in:
+16
-2
@@ -3,6 +3,8 @@
|
|||||||
//#include "../examples/helpers/AsyncFileReader.h"
|
//#include "../examples/helpers/AsyncFileReader.h"
|
||||||
//#include "../examples/helpers/AsyncFileStreamer.h"
|
//#include "../examples/helpers/AsyncFileStreamer.h"
|
||||||
|
|
||||||
|
us_listen_socket *token;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
|
|
||||||
struct PerSocketData {
|
struct PerSocketData {
|
||||||
@@ -14,12 +16,23 @@ int main(int argc, char **argv) {
|
|||||||
.key_file_name = "/home/alexhultman/key.pem",
|
.key_file_name = "/home/alexhultman/key.pem",
|
||||||
.cert_file_name = "/home/alexhultman/cert.pem",
|
.cert_file_name = "/home/alexhultman/cert.pem",
|
||||||
.passphrase = "1234"
|
.passphrase = "1234"
|
||||||
}).get("/hello", [](auto *res, auto *req) {
|
}).get("/exit", [](auto *res, auto *req) {
|
||||||
res->end("Hello HTTP!");
|
|
||||||
|
if (!token) {
|
||||||
|
res->end("Server already closed down!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
res->end("Closing down server now");
|
||||||
|
|
||||||
|
/* Use this route to signal stop listening */
|
||||||
|
us_listen_socket_close(token);
|
||||||
|
token = nullptr;
|
||||||
}).ws<PerSocketData>("/*", {
|
}).ws<PerSocketData>("/*", {
|
||||||
/* Settings */
|
/* Settings */
|
||||||
.compression = uWS::DEDICATED_COMPRESSOR,
|
.compression = uWS::DEDICATED_COMPRESSOR,
|
||||||
.maxPayloadLength = 16 * 1024 * 1024,
|
.maxPayloadLength = 16 * 1024 * 1024,
|
||||||
|
/* autoPingInterval */
|
||||||
/* Handlers */
|
/* Handlers */
|
||||||
.open = [](auto *ws, auto *req) {
|
.open = [](auto *ws, auto *req) {
|
||||||
std::cout << "WebSocket connected" << std::endl;
|
std::cout << "WebSocket connected" << std::endl;
|
||||||
@@ -48,6 +61,7 @@ int main(int argc, char **argv) {
|
|||||||
std::cout << "OK per socket data: " << (perSocketData->hello == 13) << std::endl;
|
std::cout << "OK per socket data: " << (perSocketData->hello == 13) << std::endl;
|
||||||
}
|
}
|
||||||
}).listen(9001, [](auto *token) {
|
}).listen(9001, [](auto *token) {
|
||||||
|
::token = token;
|
||||||
if (token) {
|
if (token) {
|
||||||
std::cout << "Listening on port " << 3000 << std::endl;
|
std::cout << "Listening on port " << 3000 << std::endl;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
~TemplatedApp() {
|
~TemplatedApp() {
|
||||||
|
/* Let's just put everything here */
|
||||||
|
httpContext->free();
|
||||||
}
|
}
|
||||||
|
|
||||||
TemplatedApp(const TemplatedApp &other) {
|
TemplatedApp(const TemplatedApp &other) {
|
||||||
|
|||||||
@@ -169,6 +169,15 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void freeNode(Node *node) {
|
||||||
|
for (auto *p : node->children) {
|
||||||
|
freeNode(p);
|
||||||
|
}
|
||||||
|
if (node != &tree) {
|
||||||
|
delete node;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public:
|
public:
|
||||||
HttpRouter() {
|
HttpRouter() {
|
||||||
/* Make sure unhandled is at index 0 */
|
/* Make sure unhandled is at index 0 */
|
||||||
@@ -179,6 +188,7 @@ public:
|
|||||||
|
|
||||||
~HttpRouter() {
|
~HttpRouter() {
|
||||||
// todo: delete all Nodes or use unique_ptr
|
// todo: delete all Nodes or use unique_ptr
|
||||||
|
freeNode(&tree);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* For debugging you may want to print this */
|
/* For debugging you may want to print this */
|
||||||
|
|||||||
@@ -111,6 +111,7 @@ struct DeflationStream {
|
|||||||
|
|
||||||
~DeflationStream() {
|
~DeflationStream() {
|
||||||
std::cout << "Destructing DeflationStream" << std::endl;
|
std::cout << "Destructing DeflationStream" << std::endl;
|
||||||
|
deflateEnd(&deflationStream);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user