logic: refactor a little bit

TODO: fix double free and memory corruption
This commit is contained in:
Kevin J. 2024-08-01 01:17:17 +02:00
parent 78d14a8217
commit 134c353161
2 changed files with 13 additions and 12 deletions

24
proxy.c
View File

@ -119,7 +119,6 @@ int par_line = 0;
void handle_request(int sockfd) {
int ret;
int id = getpid();
char *msgbuff = (char *) calloc(1, PROXY_MAX_MSGLEN);
if (msgbuff == NULL) {
@ -129,17 +128,14 @@ void handle_request(int sockfd) {
ret = recv(sockfd, msgbuff, PROXY_MAX_MSGLEN, 0);
if (ret < 0) {
fprintf(stderr, "[CHILD %d] Failed to receive data from client\n", id);
fprintf(stderr, "Failed to receive data from client\n");
goto end_sock;
}
fprintf(stdout, "[CHILD %d] Received data from client: %s\n", id, msgbuff);
// prepare structs
child_msg = (struct http_msg *) calloc(1, sizeof(struct http_msg));
if (child_msg == NULL) {
fprintf(stderr, "[CHILD %d] Failed to allocate memory for client"
"structs\n", id);
fprintf(stderr, "Failed to allocate memory for client structs\n");
goto end_sock;
}
@ -157,12 +153,18 @@ void handle_request(int sockfd) {
ln = strtok(NULL, "\n");
}
fprintf(stdout, "I am done here.... zzzz \n");
// logic
for (;;);
//end_structs:
//free(child_msg);
for (int i = 0; i < child_msg->header_num; i++) {
struct header *header = &child_msg->headers[i];
free(header->key);
free(header->value);
free(header);
}
free(child_msg->method);
free(child_msg->uri);
free(child_msg->ver);
free(child_msg);
end_sock:
close(sockfd);

View File

@ -29,7 +29,6 @@ struct http_msg {
char *ver;
int header_num;
struct header *headers;
void *body;
};
#endif