Replace shared_pointer with RAII, also fix root path not routing correctly
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user