Skip to content

Commit 0d26b86

Browse files
Leonardo Alminanaedsiper
authored andcommitted
http_common: added guards to prevent leaks
Signed-off-by: Leonardo Alminana <[email protected]>
1 parent e048e6f commit 0d26b86

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

src/flb_http_common.c

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,10 @@ struct flb_http_request *flb_http_request_create()
150150

151151
void flb_http_request_destroy(struct flb_http_request *request)
152152
{
153+
if (request->authority != NULL) {
154+
cfl_sds_destroy(request->authority);
155+
}
156+
153157
if (request->path != NULL) {
154158
cfl_sds_destroy(request->path);
155159
}
@@ -654,6 +658,12 @@ int flb_http_request_set_url(struct flb_http_request *request,
654658
int flb_http_request_set_uri(struct flb_http_request *request,
655659
char *uri)
656660
{
661+
if (request->path != NULL) {
662+
cfl_sds_destroy(request->path);
663+
664+
request->path = NULL;
665+
}
666+
657667
request->path = cfl_sds_create(uri);
658668

659669
if (request->path == NULL) {
@@ -666,6 +676,12 @@ int flb_http_request_set_uri(struct flb_http_request *request,
666676
int flb_http_request_set_query_string(struct flb_http_request *request,
667677
char *query_string)
668678
{
679+
if (request->query_string != NULL) {
680+
cfl_sds_destroy(request->query_string);
681+
682+
request->query_string = NULL;
683+
}
684+
669685
request->query_string = cfl_sds_create(query_string);
670686

671687
if (request->query_string == NULL) {
@@ -678,6 +694,12 @@ int flb_http_request_set_query_string(struct flb_http_request *request,
678694
int flb_http_request_set_content_type(struct flb_http_request *request,
679695
char *content_type)
680696
{
697+
if (request->content_type != NULL) {
698+
cfl_sds_destroy(request->content_type);
699+
700+
request->content_type = NULL;
701+
}
702+
681703
request->content_type = cfl_sds_create(content_type);
682704

683705
if (request->content_type == NULL) {
@@ -690,6 +712,12 @@ int flb_http_request_set_content_type(struct flb_http_request *request,
690712
int flb_http_request_set_user_agent(struct flb_http_request *request,
691713
char *user_agent)
692714
{
715+
if (request->user_agent != NULL) {
716+
cfl_sds_destroy(request->user_agent);
717+
718+
request->user_agent = NULL;
719+
}
720+
693721
request->user_agent = cfl_sds_create(user_agent);
694722

695723
if (request->user_agent == NULL) {

0 commit comments

Comments
 (0)