Fix some memory leaks

master
Nick Krichevsky 2018-09-09 23:27:50 -04:00
parent cb16b2fcd0
commit 6ba3ee9756
1 changed files with 18 additions and 0 deletions

View File

@ -190,10 +190,28 @@ enum socket_result serve_one_request(int sock_fd) {
enum socket_result read_result = get_all_remote_parts(client_fd, TYPE_SERVER, &message);
if (read_result == RESULT_MALFORMED) {
send_headers(400, client_fd, -1);
if (message.start_line != NULL) {
free(message.start_line);
}
if (message.contents != NULL) {
free(message.contents);
}
if (message.headers != NULL) {
free_headers(message.headers);
}
close(client_fd);
return RESULT_MALFORMED;
} else if (read_result != RESULT_OK){
send_headers(500, client_fd, -1);
if (message.start_line != NULL) {
free(message.start_line);
}
if (message.contents != NULL) {
free(message.contents);
}
if (message.headers != NULL) {
free_headers(message.headers);
}
close(client_fd);
return RESULT_READ_ERROR;
}