From 5b1caeeadcecd798ee4b386b15c17cb7591a8bfe Mon Sep 17 00:00:00 2001 From: Brandon Arp Date: Fri, 15 Apr 2016 11:37:44 -0700 Subject: [PATCH] fix potential curl plugin curl_slist_append memory leak make sure that we dont leak memory if curl_slist_append returns null --- src/curl.c | 7 +++++-- src/curl_json.c | 7 +++++-- src/curl_xml.c | 7 +++++-- 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/src/curl.c b/src/curl.c index 9d2196ac..8b30fa4b 100644 --- a/src/curl.c +++ b/src/curl.c @@ -165,16 +165,19 @@ static void cc_web_page_free (web_page_t *wp) /* {{{ */ static int cc_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */ oconfig_item_t *ci) { + struct curl_slist *temp = NULL; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("curl plugin: `%s' needs exactly one string argument.", name); return (-1); } - *dest = curl_slist_append(*dest, ci->values[0].value.string); - if (*dest == NULL) + temp = curl_slist_append(*dest, ci->values[0].value.string); + if (temp == NULL) return (-1); + *dest = temp; + return (0); } /* }}} int cc_config_append_string */ diff --git a/src/curl_json.c b/src/curl_json.c index 6b8449c9..2314bfe9 100644 --- a/src/curl_json.c +++ b/src/curl_json.c @@ -444,16 +444,19 @@ static c_avl_tree_t *cj_avl_create(void) static int cj_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */ oconfig_item_t *ci) { + struct curl_slist *temp = NULL; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("curl_json plugin: `%s' needs exactly one string argument.", name); return (-1); } - *dest = curl_slist_append(*dest, ci->values[0].value.string); - if (*dest == NULL) + temp = curl_slist_append(*dest, ci->values[0].value.string); + if (temp == NULL) return (-1); + *dest = temp; + return (0); } /* }}} int cj_config_append_string */ diff --git a/src/curl_xml.c b/src/curl_xml.c index d34b69ef..9483738b 100644 --- a/src/curl_xml.c +++ b/src/curl_xml.c @@ -215,16 +215,19 @@ static void cx_free (void *arg) /* {{{ */ static int cx_config_append_string (const char *name, struct curl_slist **dest, /* {{{ */ oconfig_item_t *ci) { + struct curl_slist *temp = NULL; if ((ci->values_num != 1) || (ci->values[0].type != OCONFIG_TYPE_STRING)) { WARNING ("curl_xml plugin: `%s' needs exactly one string argument.", name); return (-1); } - *dest = curl_slist_append(*dest, ci->values[0].value.string); - if (*dest == NULL) + temp = curl_slist_append(*dest, ci->values[0].value.string); + if (temp == NULL) return (-1); + *dest = temp; + return (0); } /* }}} int cx_config_append_string */ -- 2.30.2