aboutsummaryrefslogtreecommitdiff
path: root/pcap-linux.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2018-04-30 11:23:19 -0700
committerGuy Harris <guy@alum.mit.edu>2018-04-30 11:23:19 -0700
commitf365114e859b1204620b5e2503325b2842e07370 (patch)
treebbea90eb4209de6511141243b124761ec627877f /pcap-linux.c
parent7be747499ef4ce5760fd6acf84c987466072f376 (diff)
downloadlibpcap-f365114e859b1204620b5e2503325b2842e07370.tar.gz
Don't do anything with pathstr if we don't need it.
Declare it in the if() arm where it's used, and free it before we exit that arm.
Diffstat (limited to 'pcap-linux.c')
-rw-r--r--pcap-linux.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/pcap-linux.c b/pcap-linux.c
index bc8a1842..6dcd9782 100644
--- a/pcap-linux.c
+++ b/pcap-linux.c
@@ -2609,7 +2609,6 @@ static int
get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
{
int sock;
- char *pathstr;
FILE *fh;
unsigned int arptype;
struct ifreq ifr;
@@ -2639,6 +2638,8 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
* "Ethernet", i.e. ARPHRD_ETHER, for non-monitor-
* mode devices.)
*/
+ char *pathstr;
+
if (asprintf(&pathstr, "/sys/class/net/%s/type", name) == -1) {
pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
"%s: Can't generate path name string for /sys/class/net device",
@@ -2666,6 +2667,7 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
*/
close(sock);
fclose(fh);
+ free(pathstr);
return 0;
#endif
@@ -2690,9 +2692,9 @@ get_if_flags(const char *name, bpf_u_int32 *flags, char *errbuf)
}
}
fclose(fh);
+ free(pathstr);
}
}
- free(pathstr);
#ifdef ETHTOOL_GLINK
memset(&ifr, 0, sizeof(ifr));