mirror of
https://github.com/3lswear/webserv.git
synced 2025-10-28 21:07:59 +03:00
fix: segv from when empty client
This commit is contained in:
@@ -8,6 +8,7 @@ Client::Client()
|
||||
done = false;
|
||||
this->_fd = -1;
|
||||
this->_sended = 0;
|
||||
_to_send_char = NULL;
|
||||
}
|
||||
|
||||
Client::Client(char *str)
|
||||
@@ -17,11 +18,14 @@ Client::Client(char *str)
|
||||
this->_fd = -1;
|
||||
this->_buff = str;
|
||||
this->_sended = 0;
|
||||
_to_send_char = NULL;
|
||||
|
||||
|
||||
}
|
||||
|
||||
Client::Client(char *str, ServerConfig *config)
|
||||
{
|
||||
_to_send_char = NULL;
|
||||
allRead = false;
|
||||
done = false;
|
||||
this->_fd = -1;
|
||||
@@ -234,7 +238,8 @@ void Client::clear(void)
|
||||
_bodyToSend = "";
|
||||
_headerToSend = "";
|
||||
_toSend = "";
|
||||
free(_to_send_char);
|
||||
if (_to_send_char)
|
||||
free(_to_send_char);
|
||||
}
|
||||
|
||||
Client::~Client()
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user