]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Improve a tcpdump error message, free device list before exiting.
authorGuy Harris <[email protected]>
Fri, 9 Aug 2024 06:39:09 +0000 (23:39 -0700)
committerGuy Harris <[email protected]>
Fri, 9 Aug 2024 06:41:17 +0000 (23:41 -0700)
If an adapter index that's greater than the number of adapters is
specified by the user, mention the incorrect adapter index, and the
total number of adapters (the former being greater than the latter), in
the error message.

Free the adapter list before reporting the error and exiting, to
suppress complaints from leak detectots (not that the memory spends much
time leaked, as exiting destroys the entire address space, but...).

Fixes issue #1208.

(cherry picked from commit 11e8f0a2ecaf6e391ab412b1b23ece0ddac2dd0c)

tcpdump.c

index 2e3eb26c5c3c1d0bc95323cb53891b5a6c49cc63..6e6dc29cab3d9049be4ce5794d7960a9116f340c 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -1237,8 +1237,11 @@ _U_
        for (i = 0, dev = devlist; i < devnum-1 && dev != NULL;
            i++, dev = dev->next)
                ;
-       if (dev == NULL)
-               error("Invalid adapter index");
+       if (dev == NULL) {
+               pcap_freealldevs(devlist);
+               error("Invalid adapter index %ld: only %ld interfaces found",
+                   devnum, i);
+       }
        device = strdup(dev->name);
        pcap_freealldevs(devlist);
        return (device);