Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
http: fix memory leak in http_arg_get_remove(), optimize http_serve_r…
…equests()
  • Loading branch information
perexg committed Mar 11, 2015
1 parent 38b541e commit 3c889e1
Showing 1 changed file with 8 additions and 15 deletions.
23 changes: 8 additions & 15 deletions src/http.c
Expand Up @@ -801,6 +801,9 @@ http_arg_get_remove(struct http_arg_list *list, const char *name)
TAILQ_REMOVE(list, ra, link);
strncpy(buf, ra->val, sizeof(buf)-1);
buf[sizeof(buf)-1] = '\0';
free(ra->key);
free(ra->val);
free(ra);
return buf;
}
buf[0] = '\0';
Expand Down Expand Up @@ -972,7 +975,7 @@ http_serve_requests(http_connection_t *hc)
{
htsbuf_queue_t spill;
char *argv[3], *c, *cmdline = NULL, *hdrline = NULL;
int n;
int n, r;

http_arg_init(&hc->hc_args);
http_arg_init(&hc->hc_req_args);
Expand Down Expand Up @@ -1017,8 +1020,7 @@ http_serve_requests(http_connection_t *hc)
http_arg_set(&hc->hc_args, argv[0], argv[1]);
}

if(process_request(hc, &spill))
break;
r = process_request(hc, &spill);

free(hc->hc_post_data);
hc->hc_post_data = NULL;
Expand All @@ -1034,25 +1036,16 @@ http_serve_requests(http_connection_t *hc)
free(hc->hc_password);
hc->hc_password = NULL;

if (r)
break;

hc->hc_logout_cookie = 0;

} while(hc->hc_keep_alive && http_server);

error:
free(hdrline);
free(cmdline);

http_arg_flush(&hc->hc_args);
http_arg_flush(&hc->hc_req_args);

htsbuf_queue_flush(&hc->hc_reply);

free(hc->hc_post_data);
hc->hc_post_data = NULL;
free(hc->hc_username);
hc->hc_username = NULL;
free(hc->hc_password);
hc->hc_password = NULL;
}


Expand Down

0 comments on commit 3c889e1

Please sign in to comment.