mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
fix: leak in ServerConfig class
This commit is contained in:
@@ -72,10 +72,13 @@ void Server::readConfig(char *filename)
|
|||||||
|
|
||||||
arr = parser.root->find("server")->second->getMapArray();
|
arr = parser.root->find("server")->second->getMapArray();
|
||||||
it = arr->begin();
|
it = arr->begin();
|
||||||
|
ServerConfig *tmp;
|
||||||
|
|
||||||
while (it != arr->end())
|
while (it != arr->end())
|
||||||
{
|
{
|
||||||
_configs.push_back(new ServerConfig(*it));
|
tmp = new ServerConfig(*it);
|
||||||
|
_configs.push_back(tmp);
|
||||||
|
tmp->fillFields();
|
||||||
++it;
|
++it;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -309,7 +312,6 @@ void Server::start(void)
|
|||||||
else if (events & EPOLLOUT)
|
else if (events & EPOLLOUT)
|
||||||
{
|
{
|
||||||
/* DBOUT << GREEN << "doing sendData" << ENDL; */
|
/* DBOUT << GREEN << "doing sendData" << ENDL; */
|
||||||
client_map[fd]->printClientInfo();
|
|
||||||
sendData(*client_map[fd], fd);
|
sendData(*client_map[fd], fd);
|
||||||
if (client_map[fd]->allSended())
|
if (client_map[fd]->allSended())
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ ServerConfig::ServerConfig(TOMLMap *map)
|
|||||||
_clientBodySize = -1;
|
_clientBodySize = -1;
|
||||||
_port = 0;
|
_port = 0;
|
||||||
|
|
||||||
fillFields();
|
// fillFields();
|
||||||
}
|
}
|
||||||
|
|
||||||
//--------------------------------------------------GET/SET---------------------------------------
|
//--------------------------------------------------GET/SET---------------------------------------
|
||||||
@@ -199,61 +199,91 @@ int ServerConfig::putLocation(toml_node *node)
|
|||||||
if (it1->first == "location")
|
if (it1->first == "location")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::STRING)
|
if (it1->second->get_type() != toml_node::STRING)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("location", toml_node::STRING, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("location", toml_node::STRING, it1->second->get_type()));
|
||||||
|
}
|
||||||
tmp->location = *it1->second->getString();
|
tmp->location = *it1->second->getString();
|
||||||
}
|
}
|
||||||
else if (it1->first == "root")
|
else if (it1->first == "root")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::STRING)
|
if (it1->second->get_type() != toml_node::STRING)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("root", toml_node::STRING, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("root", toml_node::STRING, it1->second->get_type()));
|
||||||
|
}
|
||||||
tmp->root = *it1->second->getString();
|
tmp->root = *it1->second->getString();
|
||||||
}
|
}
|
||||||
else if (it1->first == "autoindex")
|
else if (it1->first == "autoindex")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::BOOL)
|
if (it1->second->get_type() != toml_node::BOOL)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("autoindex", toml_node::BOOL, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("autoindex", toml_node::BOOL, it1->second->get_type()));
|
||||||
|
}
|
||||||
tmp->autoindex = it1->second->getBool();
|
tmp->autoindex = it1->second->getBool();
|
||||||
}
|
}
|
||||||
else if (it1->first == "upload_accept")
|
else if (it1->first == "upload_accept")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::BOOL)
|
if (it1->second->get_type() != toml_node::BOOL)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("upload_accept", toml_node::BOOL, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("upload_accept", toml_node::BOOL, it1->second->get_type()));
|
||||||
|
}
|
||||||
tmp->uploadAccept = it1->second->getBool();
|
tmp->uploadAccept = it1->second->getBool();
|
||||||
}
|
}
|
||||||
else if (it1->first == "upload_dir")
|
else if (it1->first == "upload_dir")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::STRING)
|
if (it1->second->get_type() != toml_node::STRING)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("upload_dir", toml_node::STRING, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("upload_dir", toml_node::STRING, it1->second->get_type()));
|
||||||
|
}
|
||||||
tmp->uploadDir = *it1->second->getString();
|
tmp->uploadDir = *it1->second->getString();
|
||||||
}
|
}
|
||||||
else if (it1->first == "cgi_pass")
|
else if (it1->first == "cgi_pass")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::STRING)
|
if (it1->second->get_type() != toml_node::STRING)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("cgi_pass", toml_node::STRING, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("cgi_pass", toml_node::STRING, it1->second->get_type()));
|
||||||
|
}
|
||||||
tmp->cgi_pass = *it1->second->getString();
|
tmp->cgi_pass = *it1->second->getString();
|
||||||
}
|
}
|
||||||
else if (it1->first == "body_size_limit")
|
else if (it1->first == "body_size_limit")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::NUM)
|
if (it1->second->get_type() != toml_node::NUM)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("body_size_limit", toml_node::NUM, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("body_size_limit", toml_node::NUM, it1->second->get_type()));
|
||||||
|
}
|
||||||
tmp->clientBodySize = it1->second->getNum();
|
tmp->clientBodySize = it1->second->getNum();
|
||||||
}
|
}
|
||||||
else if (it1->first == "directory_file")
|
else if (it1->first == "directory_file")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::STRING)
|
if (it1->second->get_type() != toml_node::STRING)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("directory_file", toml_node::STRING, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("directory_file", toml_node::STRING, it1->second->get_type()));
|
||||||
|
}
|
||||||
tmp->directoryFile = *it1->second->getString();
|
tmp->directoryFile = *it1->second->getString();
|
||||||
}
|
}
|
||||||
else if (it1->first == "methods")
|
else if (it1->first == "methods")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::ARRAY)
|
if (it1->second->get_type() != toml_node::ARRAY)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("methods", toml_node::ARRAY, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("methods", toml_node::ARRAY, it1->second->get_type()));
|
||||||
|
}
|
||||||
Array = *it1->second->getArray();
|
Array = *it1->second->getArray();
|
||||||
it2 = Array.begin();
|
it2 = Array.begin();
|
||||||
while (it2 != Array.end())
|
while (it2 != Array.end())
|
||||||
{
|
{
|
||||||
if ((*it2)->get_type() != toml_node::STRING)
|
if ((*it2)->get_type() != toml_node::STRING)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("methods elem", toml_node::STRING, (*it2)->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("methods elem", toml_node::STRING, (*it2)->get_type()));
|
||||||
|
}
|
||||||
tmp->methods.push_back(*((*it2)->getString()));
|
tmp->methods.push_back(*((*it2)->getString()));
|
||||||
++it2;
|
++it2;
|
||||||
}
|
}
|
||||||
@@ -261,17 +291,29 @@ int ServerConfig::putLocation(toml_node *node)
|
|||||||
else if (it1->first == "redirect")
|
else if (it1->first == "redirect")
|
||||||
{
|
{
|
||||||
if (it1->second->get_type() != toml_node::ARRAY)
|
if (it1->second->get_type() != toml_node::ARRAY)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("redirect", toml_node::ARRAY, it1->second->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("redirect", toml_node::ARRAY, it1->second->get_type()));
|
||||||
|
}
|
||||||
Array = *it1->second->getArray();
|
Array = *it1->second->getArray();
|
||||||
if (Array.size() != 2)
|
if (Array.size() != 2)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException("The redirect field specified the wrong number of arguments!");
|
throw ConfigException("The redirect field specified the wrong number of arguments!");
|
||||||
|
}
|
||||||
it2 = Array.begin();
|
it2 = Array.begin();
|
||||||
if ((*it2)->get_type() != toml_node::STRING)
|
if ((*it2)->get_type() != toml_node::STRING)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("redirect elem", toml_node::STRING, (*it2)->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("redirect elem", toml_node::STRING, (*it2)->get_type()));
|
||||||
|
}
|
||||||
str = *(*it2)->getString();
|
str = *(*it2)->getString();
|
||||||
++it2;
|
++it2;
|
||||||
if ((*it2)->get_type() != toml_node::STRING)
|
if ((*it2)->get_type() != toml_node::STRING)
|
||||||
|
{
|
||||||
|
delete tmp;
|
||||||
throw ConfigException(getWrongTypeErrorMSG("redirect elem", toml_node::STRING, (*it2)->get_type()));
|
throw ConfigException(getWrongTypeErrorMSG("redirect elem", toml_node::STRING, (*it2)->get_type()));
|
||||||
|
}
|
||||||
tmp->redirect.insert(std::make_pair(atoi(str.c_str()), *(*it2)->getString()));
|
tmp->redirect.insert(std::make_pair(atoi(str.c_str()), *(*it2)->getString()));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Reference in New Issue
Block a user