Replace shared_pointer with RAII, also fix root path not routing correctly

This commit is contained in:
Pablu23
2024-11-26 17:29:36 +01:00
parent c18d5f993d
commit af0c6fb814
5 changed files with 37 additions and 26 deletions

View File

@@ -4,7 +4,6 @@
#include <csignal>
#include <cstdint>
#include <iostream>
#include <memory>
#include <mutex>
#include <strings.h>
#include <sys/select.h>
@@ -21,6 +20,12 @@ Router::Router(int port) {
m_running = false;
}
Router::~Router() {
for (auto t : m_routes) {
delete t.second;
}
}
int Router::start() {
m_running = true;
int err = bind(m_socket, (struct sockaddr *)&m_address, sizeof(m_address));
@@ -105,7 +110,7 @@ void Router::handle(std::string pathPattern,
// TODO: UNSAFE CHECK BOUNDS
auto tree = m_routes[route[0]];
if (!tree) {
tree = std::make_shared<Tree>(Tree(route[0]));
tree = new Tree(route[0]);
m_routes.insert_or_assign(route[0], tree);
}
tree->add_path(route[1], func);