diff options
author | Gisle Vanem <gisle.vanem@gmail.com> | 2017-09-20 09:05:10 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2017-09-23 00:20:20 -0700 |
commit | 367575984881bff71e6b40cad02b5cb365ab346b (patch) | |
tree | 23ec403477a7a635117da9197021268b30c21fb4 /tests | |
parent | 0a4cfeac9546ecf691f66dc62164ff8e1e5d414e (diff) | |
download | libpcap-367575984881bff71e6b40cad02b5cb365ab346b.tar.gz |
Plug some resource (memory) leaks:
findalldevstest.c:
Need to call 'pcap_freealldevs()'.
filtertest.c:
If filter is missing from command-line, warn and exit.
Call 'pcap_freecode()' and 'free(cmdbuf)' before exit.
capturetest.c:
Call 'pcap_freecode()' before exit.
Diffstat (limited to 'tests')
-rw-r--r-- | tests/capturetest.c | 1 | ||||
-rw-r--r-- | tests/filtertest.c | 8 | ||||
-rw-r--r-- | tests/findalldevstest.c | 3 |
3 files changed, 11 insertions, 1 deletions
diff --git a/tests/capturetest.c b/tests/capturetest.c index f4179c6b..a431cbc0 100644 --- a/tests/capturetest.c +++ b/tests/capturetest.c @@ -201,6 +201,7 @@ main(int argc, char **argv) program_name, pcap_geterr(pd)); } pcap_close(pd); + pcap_freecode(&fcode); exit(status == -1 ? 1 : 0); } diff --git a/tests/filtertest.c b/tests/filtertest.c index a79fb25f..20fa4418 100644 --- a/tests/filtertest.c +++ b/tests/filtertest.c @@ -191,6 +191,7 @@ main(int argc, char **argv) long snaplen; char *p; int dlt; + int have_fcode = 0; bpf_u_int32 netmask = PCAP_NETMASK_UNKNOWN; char *cmdbuf; pcap_t *pd; @@ -279,6 +280,9 @@ main(int argc, char **argv) else cmdbuf = copy_argv(&argv[optind+1]); + if (!cmdbuf) + error("I need a filter to work with."); + pd = pcap_open_dead(dlt, snaplen); if (pd == NULL) error("Can't open fake pcap_t"); @@ -286,6 +290,7 @@ main(int argc, char **argv) if (pcap_compile(pd, &fcode, cmdbuf, Oflag, netmask) < 0) error("%s", pcap_geterr(pd)); + have_fcode = 1; if (!bpf_validate(fcode.bf_insns, fcode.bf_len)) warn("Filter doesn't pass validation"); @@ -301,6 +306,9 @@ main(int argc, char **argv) #endif bpf_dump(&fcode, dflag); + free(cmdbuf); + if (have_fcode) + pcap_freecode (&fcode); pcap_close(pd); exit(0); } diff --git a/tests/findalldevstest.c b/tests/findalldevstest.c index ef866920..e7f3caab 100644 --- a/tests/findalldevstest.c +++ b/tests/findalldevstest.c @@ -56,7 +56,7 @@ win32_strerror(DWORD error) pcap_snprintf(p, ERRBUF_SIZE+1-(p-errbuf), " (%lu)", error); return errbuf; } - + static char * getpass(const char *prompt) { @@ -163,6 +163,7 @@ int main(int argc, char **argv) } } + pcap_freealldevs(alldevs); exit(exit_status); } |