Skip to content

Commit

Permalink
Minor bug in free http_request, and free custom_headers pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
m0hithreddy committed Dec 12, 2020
1 parent 9e7e571 commit 8901821
Showing 1 changed file with 20 additions and 13 deletions.
33 changes: 20 additions & 13 deletions src/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,19 +642,22 @@ int free_http_request(struct http_request** _s_request) {
struct http_request* s_request = *_s_request;

/* Freeing request header values */
for (int hdr_count = 0; hdr_count < HTTP_CONSTANT_RESPONSE_HEADERS_COUNT; hdr_count++) {
for (int hdr_count = 0; hdr_count < HTTP_CONSTANT_REQUEST_HEADERS_COUNT; hdr_count++) {
free(*((char**) ((void*) s_request + hdr_count * sizeof(char*))));
}

/* Freeing custom header values */
int chdr_count = 0;
if (s_request->custom_headers != NULL) {
int chdr_count = 0;

for ( ; s_request->custom_headers != NULL && s_request->custom_headers[chdr_count] != NULL; \
chdr_count++) {
free(s_request->custom_headers[chdr_count][0]);
free(s_request->custom_headers[chdr_count][1]);
for ( ; s_request->custom_headers[chdr_count] != NULL; chdr_count++) {
free(s_request->custom_headers[chdr_count][0]);
free(s_request->custom_headers[chdr_count][1]);

free(s_request->custom_headers[chdr_count]);
}

free(s_request->custom_headers[chdr_count]);
free(s_request->custom_headers);
}

/* Freeing Request Body */
Expand Down Expand Up @@ -684,13 +687,17 @@ int free_http_response(struct http_response** _s_response) {
}

/* Freeing custom header values */
int chdr_count = 0;
if (s_response->custom_headers != NULL) {
int chdr_count = 0;

for ( ; s_response->custom_headers != NULL && s_response->custom_headers[chdr_count] != NULL; chdr_count++) {
free(s_response->custom_headers[chdr_count][0]);
free(s_response->custom_headers[chdr_count][1]);
for ( ; s_response->custom_headers[chdr_count] != NULL; chdr_count++) {
free(s_response->custom_headers[chdr_count][0]);
free(s_response->custom_headers[chdr_count][1]);

free(s_response->custom_headers[chdr_count]);
free(s_response->custom_headers[chdr_count]);
}

free(s_response->custom_headers);
}

/* Freeing Response Body */
Expand All @@ -702,4 +709,4 @@ int free_http_response(struct http_response** _s_response) {
*_s_response = NULL;

return PROXY_ERROR_NONE;
}
}

0 comments on commit 8901821

Please sign in to comment.