net-snmp / net-snmp

A SNMP application library, tools and daemon

Repository from Github https://github.comnet-snmp/net-snmpRepository from Github https://github.comnet-snmp/net-snmp

leak of socket in netsnmp_unix_transport() function

leeriorio opened this issue · comments

Hello! In result of static analyse of net-snmp sources with Svace static analyzer I found minor error of cathegory "HANDLE_LEAK", which means that there is potential error with memory usage. There is creation of socket:

t->sock = socket(PF_UNIX, SOCK_STREAM, 0);

then, if we run unstructions in lines 363-364 below

if (t->local == NULL) {
netsnmp_transport_free(t);
return NULL;
but calling netsnmp_transport_free() won't clear memory in t->sock, isn't it?

void
netsnmp_transport_free(netsnmp_transport *t)
{
if (NULL == t)
return;
#ifndef FEATURE_REMOVE_TRANSPORT_CACHE
/** don't free a transport that is currently shared */
if (netsnmp_transport_cache_remove(t) == 1)
return;
#endif
SNMP_FREE(t->local);
SNMP_FREE(t->remote);
SNMP_FREE(t->data);
netsnmp_transport_free(t->base_transport);
SNMP_FREE(t);
}

Found by Linux Verification Center (portal.linuxtesting.ru) with SVACE.
Author E.Zilotina.