mirror of
https://github.com/KeyZox71/webserv.git
synced 2025-05-10 20:28:46 +02:00
「🔨」 fix: fixed leak
This commit is contained in:
@ -27,7 +27,7 @@ redirect = "https://kanel.ovh"
|
|||||||
|
|
||||||
[serverr]
|
[serverr]
|
||||||
server_names = { "ptnnnn.local"}
|
server_names = { "ptnnnn.local"}
|
||||||
host = "127.0.0.2"
|
host = "127.0.0.1"
|
||||||
port = 9090
|
port = 9090
|
||||||
|
|
||||||
[serverr.error_pages]
|
[serverr.error_pages]
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/14 14:14:39 by adjoly #+# #+# */
|
/* Created: 2025/04/14 14:14:39 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/04/25 15:28:10 by adjoly ### ########.fr */
|
/* Updated: 2025/04/25 17:03:34 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -24,9 +24,10 @@ namespace server {
|
|||||||
class Client {
|
class Client {
|
||||||
public:
|
public:
|
||||||
Client(struct pollfd *, sockaddr_in, config::Config *);
|
Client(struct pollfd *, sockaddr_in, config::Config *);
|
||||||
void parse(void);
|
Client(const Client &cpy);
|
||||||
virtual ~Client(void);
|
virtual ~Client(void);
|
||||||
|
|
||||||
|
void parse(void);
|
||||||
void answer(void);
|
void answer(void);
|
||||||
|
|
||||||
struct pollfd *getPollfd(void) const { return _pfd; }
|
struct pollfd *getPollfd(void) const { return _pfd; }
|
||||||
@ -37,14 +38,9 @@ class Client {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool isToClose() {
|
|
||||||
return _toClose;
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void _getRequest(std::string);
|
void _getRequest(std::string);
|
||||||
|
|
||||||
bool _toClose;
|
|
||||||
struct pollfd *_pfd;
|
struct pollfd *_pfd;
|
||||||
struct sockaddr_in _client_addr;
|
struct sockaddr_in _client_addr;
|
||||||
http::IRequest *_request;
|
http::IRequest *_request;
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/11 17:45:43 by adjoly #+# #+# */
|
/* Created: 2025/04/11 17:45:43 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/04/25 15:16:52 by adjoly ### ########.fr */
|
/* Updated: 2025/04/25 17:20:12 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -73,8 +73,6 @@ class Server {
|
|||||||
|
|
||||||
Client *_getClient(int);
|
Client *_getClient(int);
|
||||||
|
|
||||||
void _destroy_clients(void);
|
|
||||||
|
|
||||||
config::Config
|
config::Config
|
||||||
*_conf; // Pointer to the configuration class (with all config in)
|
*_conf; // Pointer to the configuration class (with all config in)
|
||||||
Logger *_log; // Pointer to the log class
|
Logger *_log; // Pointer to the log class
|
||||||
|
@ -6,7 +6,7 @@
|
|||||||
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
/* By: mmoussou <mmoussou@student.42angouleme.fr +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
|
/* Created: 2025/04/17 11:12:41 by mmoussou #+# #+# */
|
||||||
/* Updated: 2025/04/25 15:28:08 by adjoly ### ########.fr */
|
/* Updated: 2025/04/25 17:03:35 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
@ -17,10 +17,16 @@
|
|||||||
using namespace webserv::server;
|
using namespace webserv::server;
|
||||||
|
|
||||||
Client::Client(struct pollfd *pfd, sockaddr_in socket, config::Config *conf)
|
Client::Client(struct pollfd *pfd, sockaddr_in socket, config::Config *conf)
|
||||||
: _toClose(false), _pfd(pfd), _client_addr(socket), _Gconf(conf) {
|
: _pfd(pfd), _client_addr(socket), _Gconf(conf) {
|
||||||
log("➕", "Client", "constructor called");
|
log("➕", "Client", "constructor called");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Client::Client(const Client &cpy) {
|
||||||
|
if (this != &cpy) {
|
||||||
|
_pfd->fd = cpy._pfd->fd;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void Client::parse(void) {
|
void Client::parse(void) {
|
||||||
std::string received_data;
|
std::string received_data;
|
||||||
char buffer[BUFFER_SIZE];
|
char buffer[BUFFER_SIZE];
|
||||||
@ -83,6 +89,5 @@ void Client::answer(void) {
|
|||||||
|
|
||||||
Client::~Client(void) {
|
Client::~Client(void) {
|
||||||
log("➖", "Client", "destructor called");
|
log("➖", "Client", "destructor called");
|
||||||
//delete _pfd;
|
|
||||||
delete (http::Get *)(this->_request);
|
delete (http::Get *)(this->_request);
|
||||||
}
|
}
|
||||||
|
@ -6,11 +6,12 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */
|
/* Created: 2025/04/11 16:11:40 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/04/25 15:21:43 by adjoly ### ########.fr */
|
/* Updated: 2025/04/25 17:21:54 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
#include "cppeleven.hpp"
|
#include "cppeleven.hpp"
|
||||||
|
#include <algorithm>
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@ -145,11 +146,10 @@ void Server::_run(void) {
|
|||||||
|
|
||||||
for (size_t i = _fds_server.size(); i < _client_fds.size(); ++i) {
|
for (size_t i = _fds_server.size(); i < _client_fds.size(); ++i) {
|
||||||
if (_client_fds[i].revents & POLLERR) {
|
if (_client_fds[i].revents & POLLERR) {
|
||||||
close(_client_fds[i].fd);
|
// close(_client_fds[i].fd);
|
||||||
_client_fds.erase(_client_fds.begin() + i);
|
//_client_fds.erase(_client_fds.begin() + i);
|
||||||
delete _client_data[i - _fds_server.size()];
|
// delete _client_data[i - _fds_server.size()];
|
||||||
_client_data.erase(_client_data.begin() + i);
|
//_client_data.erase(_client_data.begin() + i);
|
||||||
i--;
|
|
||||||
} else if (_client_fds[i].revents & POLLIN) {
|
} else if (_client_fds[i].revents & POLLIN) {
|
||||||
Client *client = _getClient(_client_fds[i].fd);
|
Client *client = _getClient(_client_fds[i].fd);
|
||||||
if (client == not_nullptr) {
|
if (client == not_nullptr) {
|
||||||
@ -164,10 +164,18 @@ void Server::_run(void) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
client->answer();
|
client->answer();
|
||||||
|
_client_data.erase(std::find(_client_data.begin(),
|
||||||
|
_client_data.end(), client));
|
||||||
|
delete client;
|
||||||
|
for (auto it = range (_client_fds)) {
|
||||||
|
if (_client_fds[i].fd == (*it).fd) {
|
||||||
|
_client_fds.erase(it);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
close(_client_fds[i].fd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_destroy_clients();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6,10 +6,12 @@
|
|||||||
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
/* By: adjoly <adjoly@student.42angouleme.fr> +#+ +:+ +#+ */
|
||||||
/* +#+#+#+#+#+ +#+ */
|
/* +#+#+#+#+#+ +#+ */
|
||||||
/* Created: 2025/04/17 11:58:42 by adjoly #+# #+# */
|
/* Created: 2025/04/17 11:58:42 by adjoly #+# #+# */
|
||||||
/* Updated: 2025/04/25 15:17:55 by adjoly ### ########.fr */
|
/* Updated: 2025/04/25 17:19:55 by adjoly ### ########.fr */
|
||||||
/* */
|
/* */
|
||||||
/* ************************************************************************** */
|
/* ************************************************************************** */
|
||||||
|
|
||||||
|
#include "cppeleven.hpp"
|
||||||
|
#include <algorithm>
|
||||||
#include <netinet/in.h>
|
#include <netinet/in.h>
|
||||||
#include <server/Client.hpp>
|
#include <server/Client.hpp>
|
||||||
#include <server/default.hpp>
|
#include <server/default.hpp>
|
||||||
@ -17,6 +19,7 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
using namespace webserv::server;
|
using namespace webserv::server;
|
||||||
|
|
||||||
@ -81,10 +84,11 @@ int Server::_createSocket(std::string host, int port) {
|
|||||||
return (fd);
|
return (fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Server::_destroy_clients() {
|
std::vector<struct pollfd>::iterator getPfd(int fd, std::vector<struct pollfd> &s) {
|
||||||
for (auto it = range(_client_data)) {
|
for (auto it = range(s)) {
|
||||||
if ((*it)->isToClose()) {
|
if ((*it).fd == fd) {
|
||||||
delete (*it);
|
return it;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return s.end();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user