]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Free the list of devices after printing it (-D) 483/head
authorSimon Nicolussi <[email protected]>
Thu, 24 Sep 2015 19:45:59 +0000 (21:45 +0200)
committerSimon Nicolussi <[email protected]>
Thu, 24 Sep 2015 20:59:38 +0000 (22:59 +0200)
It doesn't make much of a difference because of the exit(0) right
afterwards, but prevents Valgrind from complaining about a leak.

tcpdump.c

index 50b9c3ae1e8b9773bfd7eadb437e37ca670e1049..2dac01aad5b8067d85ecc00e74409a7bdfed0fab 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -299,23 +299,21 @@ show_dlts_and_exit(const char *device)
 static void
 show_devices_and_exit (void)
 {
-       pcap_if_t *devpointer;
+       pcap_if_t *p, *devpointer;
        char ebuf[PCAP_ERRBUF_SIZE];
        int i;
 
        if (pcap_findalldevs(&devpointer, ebuf) < 0)
                error("%s", ebuf);
-       else {
-               for (i = 0; devpointer != NULL; i++) {
-                       printf("%d.%s", i+1, devpointer->name);
-                       if (devpointer->description != NULL)
-                               printf(" (%s)", devpointer->description);
-                       if (devpointer->flags != 0)
-                               printf(" [%s]", bittok2str(status_flags, "none", devpointer->flags));
-                       printf("\n");
-                       devpointer = devpointer->next;
-               }
+       for (i = 0, p = devpointer; p != NULL; i++, p = p->next) {
+               printf("%d.%s", i+1, p->name);
+               if (p->description != NULL)
+                       printf(" (%s)", p->description);
+               if (p->flags != 0)
+                       printf(" [%s]", bittok2str(status_flags, "none", p->flags));
+               printf("\n");
        }
+       pcap_freealldevs(devpointer);
        exit(0);
 }
 #endif /* HAVE_PCAP_FINDALLDEVS */