Skip to content

Commit

Permalink
Fix: memory leak
Browse files Browse the repository at this point in the history
Always free name.

Bug Summary
File:	nasl_host.c
Warning:	line 566, column 10
Potential memory leak

For testing:
run the following script
`sudo openvas-nasl -X -d -i /home/jnicola/install/var/lib/openvas/plugins/ same_host.nasl`

script:
``` nasl
display (same_host("localhost", "localhost1", cmp_hostnames: 0));
display (same_host("localhost", "localhost1", cmp_hostnames: 1));

display (same_host("127.0.0.1", "localhost1", cmp_hostnames: 0));
display (same_host("127.0.0.1", "localhost1", cmp_hostnames: 1));

display (same_host("127.0.0.2", "localhost1", cmp_hostnames: 0));
display (same_host("127.0.0.2", "localhost1", cmp_hostnames: 1));

display (same_host("localhost", "localhost2", cmp_hostnames: 0));
display (same_host("localhost", "localhost2", cmp_hostnames: 1));

display (same_host("127.0.0.1", "127.0.0.2", cmp_hostnames: 0));
display (same_host("127.0.0.1", "127.0.0.2", cmp_hostnames: 1));
```
  • Loading branch information
jjnicola committed Oct 21, 2022
1 parent 845380f commit 69b93de
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions nasl/nasl_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -554,15 +554,15 @@ nasl_same_host (lex_ctxt *lexic)

for (i = 0; i < 2; i++)
g_free (a[i]);
if (cmp_hostname)
{
//if (cmp_hostname)
// {
for (i = 0; i < 2; i++)
{
for (j = 0; j < names_nb[i]; j++)
g_free (names[i][j]);
g_free (names[i]);
}
}
// }
return retc;
}

Expand Down

0 comments on commit 69b93de

Please sign in to comment.