Skip to content

Commit

Permalink
http_client: proper free for curl params in case of failover connection
Browse files Browse the repository at this point in the history
(cherry picked from commit 9ce3820)
  • Loading branch information
miconda committed Aug 30, 2017
1 parent a7e5d2e commit 804ba55
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions src/modules/http_client/functions.c
Expand Up @@ -464,12 +464,15 @@ int curl_get_redirect(struct sip_msg* _m, const str *connection, str* result)


/*! Run a query based on a connection definition */
int curl_con_query_url_f(struct sip_msg* _m, const str *connection, const str* url, str* result, const char *contenttype, const str* post, int failover)
int curl_con_query_url_f(struct sip_msg* _m, const str *connection,
const str* url, str* result, const char *contenttype,
const str* post, int failover)
{
curl_con_t *conn = NULL;
curl_con_pkg_t *pconn = NULL;
char *urlbuf = NULL;
char *postdata = NULL;
char *failovercon = NULL;
curl_query_t query_params;

unsigned int maxdatasize = default_maxdatasize;
Expand All @@ -495,7 +498,6 @@ int curl_con_query_url_f(struct sip_msg* _m, const str *connection, const str* u
LM_DBG("******** CURL Connection found %.*s\n", connection->len, connection->s);
maxdatasize = conn->maxdatasize;


if (url && (url->len > 0) && (url->s != NULL)) {
int url_len = conn->schema.len + 3 + conn->url.len + 1 + url->len + 1;
urlbuf = pkg_malloc(url_len);
Expand Down Expand Up @@ -552,7 +554,10 @@ int curl_con_query_url_f(struct sip_msg* _m, const str *connection, const str* u
query_params.oneline = 0;
query_params.maxdatasize = maxdatasize;
query_params.http_proxy_port = conn->http_proxy_port;
query_params.failovercon = conn->failover.s ? as_asciiz(&conn->failover) : NULL;
if(conn->failover.s) {
failovercon = as_asciiz(&conn->failover);
}
query_params.failovercon = failovercon;
query_params.pconn = pconn;
if (conn->http_proxy) {
query_params.http_proxy = conn->http_proxy;
Expand All @@ -567,14 +572,19 @@ int curl_con_query_url_f(struct sip_msg* _m, const str *connection, const str* u
int counter = failover + 1;
if (counter >= 2) {
LM_DBG("**** No more failovers - returning failure\n");
return (res - 1000);
res = (res - 1000);
goto error;
}
/* Time for failover */
return curl_con_query_url_f(_m, &conn->failover, url, result, contenttype, post, counter);
res = curl_con_query_url_f(_m, &conn->failover, url, result,
contenttype, post, counter);
}

LM_DBG("***** #### ***** CURL DONE : %s \n", urlbuf);
LM_DBG("***** #### ***** CURL DONE: %s (%d)\n", urlbuf, res);
error:
if (failovercon != NULL) {
pkg_free(failovercon);
}
if (urlbuf != NULL) {
pkg_free(urlbuf);
}
Expand Down

0 comments on commit 804ba55

Please sign in to comment.