diff --git a/src/Client/Client.cpp b/src/Client/Client.cpp index c81ecd9..d34b27c 100644 --- a/src/Client/Client.cpp +++ b/src/Client/Client.cpp @@ -4,27 +4,28 @@ Client::Client() { - DBOUT << "Client constructor " << this << ENDL; allRead = false; done = false; this->_fd = -1; this->_sended = 0; + _to_send_char = NULL; } Client::Client(char *str) { - DBOUT << "Client constructor " << this << ENDL; allRead = false; done = false; this->_fd = -1; this->_buff = str; this->_sended = 0; + _to_send_char = NULL; + } Client::Client(char *str, ServerConfig *config) { - DBOUT << "Client constructor " << this << ENDL; + _to_send_char = NULL; allRead = false; done = false; this->_fd = -1; @@ -237,10 +238,11 @@ void Client::clear(void) _bodyToSend = ""; _headerToSend = ""; _toSend = ""; - free(_to_send_char); + if (_to_send_char) + free(_to_send_char); } Client::~Client() { - DBOUT << "client destructor called " << this << ENDL; + DBOUT << "client destructor called" << ENDL; } diff --git a/src/Server/Server.cpp b/src/Server/Server.cpp index fa1898b..8b37e17 100644 --- a/src/Server/Server.cpp +++ b/src/Server/Server.cpp @@ -87,7 +87,7 @@ void Server::readSocket(Client &client, int fd) int status; int bytes_read; - char buf[BUFFSIZE + 1] = {0}; + char buf[BUFFSIZE + 1]; DBOUT << TURQ << "IN readSocket" << RESET << std::endl; DBOUT << "client in readSocket "<< &client << ENDL; @@ -97,6 +97,7 @@ void Server::readSocket(Client &client, int fd) client.allRead = true; return; } + buf[bytes_read + 1] = '\0'; client.setRawData(buf); client.increaseRecvCounter(bytes_read); status = client.parseRequest();