logic: refactor a little bit
TODO: fix double free and memory corruption
This commit is contained in:
parent
78d14a8217
commit
134c353161
24
proxy.c
24
proxy.c
|
@ -119,7 +119,6 @@ int par_line = 0;
|
||||||
|
|
||||||
void handle_request(int sockfd) {
|
void handle_request(int sockfd) {
|
||||||
int ret;
|
int ret;
|
||||||
int id = getpid();
|
|
||||||
|
|
||||||
char *msgbuff = (char *) calloc(1, PROXY_MAX_MSGLEN);
|
char *msgbuff = (char *) calloc(1, PROXY_MAX_MSGLEN);
|
||||||
if (msgbuff == NULL) {
|
if (msgbuff == NULL) {
|
||||||
|
@ -129,17 +128,14 @@ void handle_request(int sockfd) {
|
||||||
|
|
||||||
ret = recv(sockfd, msgbuff, PROXY_MAX_MSGLEN, 0);
|
ret = recv(sockfd, msgbuff, PROXY_MAX_MSGLEN, 0);
|
||||||
if (ret < 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;
|
goto end_sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "[CHILD %d] Received data from client: %s\n", id, msgbuff);
|
|
||||||
|
|
||||||
// prepare structs
|
// prepare structs
|
||||||
child_msg = (struct http_msg *) calloc(1, sizeof(struct http_msg));
|
child_msg = (struct http_msg *) calloc(1, sizeof(struct http_msg));
|
||||||
if (child_msg == NULL) {
|
if (child_msg == NULL) {
|
||||||
fprintf(stderr, "[CHILD %d] Failed to allocate memory for client"
|
fprintf(stderr, "Failed to allocate memory for client structs\n");
|
||||||
"structs\n", id);
|
|
||||||
goto end_sock;
|
goto end_sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,12 +153,18 @@ void handle_request(int sockfd) {
|
||||||
ln = strtok(NULL, "\n");
|
ln = strtok(NULL, "\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stdout, "I am done here.... zzzz \n");
|
// logic
|
||||||
|
|
||||||
for (;;);
|
for (int i = 0; i < child_msg->header_num; i++) {
|
||||||
|
struct header *header = &child_msg->headers[i];
|
||||||
//end_structs:
|
free(header->key);
|
||||||
//free(child_msg);
|
free(header->value);
|
||||||
|
free(header);
|
||||||
|
}
|
||||||
|
free(child_msg->method);
|
||||||
|
free(child_msg->uri);
|
||||||
|
free(child_msg->ver);
|
||||||
|
free(child_msg);
|
||||||
|
|
||||||
end_sock:
|
end_sock:
|
||||||
close(sockfd);
|
close(sockfd);
|
||||||
|
|
Loading…
Reference in New Issue
Block a user