From: Florian Forster Date: Wed, 15 Nov 2017 20:38:32 +0000 (+0100) Subject: snmp_agent plugin: Fix memory leak. X-Git-Tag: collectd-5.8.0~10^2 X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7a8ce497dc369ffee8d942616e808a5abfca9d3e;p=collectd.git snmp_agent plugin: Fix memory leak. Allocate "entry" later so that the error handling blocks don't leak it. CID: 179244 --- diff --git a/src/snmp_agent.c b/src/snmp_agent.c index 497d157c..948107b5 100644 --- a/src/snmp_agent.c +++ b/src/snmp_agent.c @@ -1117,12 +1117,6 @@ static int snmp_agent_config_table(oconfig_item_t *ci) { } } - llentry_t *entry = llentry_create(td->name, td); - if (entry == NULL) { - snmp_agent_free_table(&td); - return -ENOMEM; - } - td->instance_index = c_avl_create((int (*)(const void *, const void *))strcmp); if (td->instance_index == NULL) { @@ -1137,6 +1131,11 @@ static int snmp_agent_config_table(oconfig_item_t *ci) { return -ENOMEM; } + llentry_t *entry = llentry_create(td->name, td); + if (entry == NULL) { + snmp_agent_free_table(&td); + return -ENOMEM; + } llist_append(g_agent->tables, entry); return 0;