Skip to content

Commit

Permalink
Fix: more memory leaks found via ccc-analyzer
Browse files Browse the repository at this point in the history
Bug Summary
File:	nasl/nasl_snmp.c
Warning:	line 657, column 12
Potential leak of memory pointed to by 'result'

Bug Summary
File:	nasl/nasl_snmp.c
Warning:	line 657, column 12
Potential leak of memory pointed to by 'request'
  • Loading branch information
jjnicola committed Oct 21, 2022
1 parent f9298a0 commit 8b2558b
Showing 1 changed file with 14 additions and 4 deletions.
18 changes: 14 additions & 4 deletions nasl/nasl_snmp.c
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,6 @@ nasl_snmpv1v2c_get (lex_ctxt *lexic, int version, u_char action)
static char *next_oid_str;

request = g_malloc0 (sizeof (struct snmpv1v2_request));
result = g_malloc0 (sizeof (struct snmp_result));

request->version = version;
request->action = action;
Expand All @@ -654,15 +653,26 @@ nasl_snmpv1v2c_get (lex_ctxt *lexic, int version, u_char action)
request->oid_str = oid_str;

if (!proto || !request->community || !request->oid_str)
return array_from_snmp_error (-2, "Missing function argument");
{
g_free (request);
return array_from_snmp_error (-2, "Missing function argument");
}
if (port < 0 || port > 65535)
return array_from_snmp_error (-2, "Invalid port value");
{
g_free (request);
return array_from_snmp_error (-2, "Invalid port value");
}
if (!proto_is_valid (proto))
return array_from_snmp_error (-2, "Invalid protocol value");
{
g_free (request);
return array_from_snmp_error (-2, "Invalid protocol value");
}

g_snprintf (peername, sizeof (peername), "%s:%s:%d", proto,
plug_get_host_ip_str (lexic->script_infos), port);
request->peername = peername;

result = g_malloc0 (sizeof (struct snmp_result));
ret = snmpv1v2c_get (request, result);

// Hack the OID string to adjust format. Replace 'iso.' with '.1.'
Expand Down

0 comments on commit 8b2558b

Please sign in to comment.