Code

write_sensu plugin: fix two resource leaks on error
authorRuben Kerkhof <ruben@rubenkerkhof.com>
Sat, 5 Dec 2015 10:47:46 +0000 (11:47 +0100)
committerFlorian Forster <octo@collectd.org>
Sat, 5 Dec 2015 20:25:30 +0000 (21:25 +0100)
CID #37999

Signed-off-by: Florian Forster <octo@collectd.org>
src/write_sensu.c

index f7803e86a24cf1194dd7ee2d1651b1a4d8628694..507018fdd1f6a7688a0672679fdcd63628d58fe3 100644 (file)
@@ -680,6 +680,7 @@ static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */
        char *handlers_str = build_json_str_list("handlers", &(host->notification_handlers));
        if (handlers_str == NULL) {
                ERROR("write_sensu plugin: Unable to alloc memory");
+               free(ret_str);
                return NULL;
        }
        // incorporate the handlers
@@ -781,6 +782,7 @@ static char *sensu_notification_to_json(struct sensu_host *host, /* {{{ */
                char *msg = replace_json_reserved(n->message);
                if (msg == NULL) {
                        ERROR("write_sensu plugin: Unable to alloc memory");
+                       free(ret_str);
                        return NULL;
                }
                res = asprintf(&temp_str, "%s, \"output\": \"%s - %s\"", ret_str, severity, msg);