Fix a few memory leaks

This commit is contained in:
Alex Hultman
2018-12-30 17:17:22 +01:00
parent 4407beedf7
commit 6618f7194b
4 changed files with 29 additions and 3 deletions
+16 -2
View File
@@ -3,6 +3,8 @@
//#include "../examples/helpers/AsyncFileReader.h"
//#include "../examples/helpers/AsyncFileStreamer.h"
us_listen_socket *token;
int main(int argc, char **argv) {
struct PerSocketData {
@@ -14,12 +16,23 @@ int main(int argc, char **argv) {
.key_file_name = "/home/alexhultman/key.pem",
.cert_file_name = "/home/alexhultman/cert.pem",
.passphrase = "1234"
}).get("/hello", [](auto *res, auto *req) {
res->end("Hello HTTP!");
}).get("/exit", [](auto *res, auto *req) {
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>("/*", {
/* Settings */
.compression = uWS::DEDICATED_COMPRESSOR,
.maxPayloadLength = 16 * 1024 * 1024,
/* autoPingInterval */
/* Handlers */
.open = [](auto *ws, auto *req) {
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;
}
}).listen(9001, [](auto *token) {
::token = token;
if (token) {
std::cout << "Listening on port " << 3000 << std::endl;
}
+2 -1
View File
@@ -55,7 +55,8 @@ public:
}
~TemplatedApp() {
/* Let's just put everything here */
httpContext->free();
}
TemplatedApp(const TemplatedApp &other) {
+10
View File
@@ -169,6 +169,15 @@ private:
}
}
void freeNode(Node *node) {
for (auto *p : node->children) {
freeNode(p);
}
if (node != &tree) {
delete node;
}
}
public:
HttpRouter() {
/* Make sure unhandled is at index 0 */
@@ -179,6 +188,7 @@ public:
~HttpRouter() {
// todo: delete all Nodes or use unique_ptr
freeNode(&tree);
}
/* For debugging you may want to print this */
+1
View File
@@ -111,6 +111,7 @@ struct DeflationStream {
~DeflationStream() {
std::cout << "Destructing DeflationStream" << std::endl;
deflateEnd(&deflationStream);
}
};