Skip to content
This repository has been archived by the owner on Nov 15, 2022. It is now read-only.

Commit

Permalink
Improve a tcpdump error message, free device list before exiting.
Browse files Browse the repository at this point in the history
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 11e8f0a)
  • Loading branch information
guyharris committed Aug 9, 2024
1 parent 7ffcbcd commit 830c52e
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions tcpdump.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 830c52e

Please sign in to comment.