diff options
author | Guy Harris <guy@alum.mit.edu> | 2018-04-30 11:23:19 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2018-04-30 11:23:19 -0700 |
commit | f365114e859b1204620b5e2503325b2842e07370 (patch) | |
tree | bbea90eb4209de6511141243b124761ec627877f /pcap-linux.c | |
parent | 7be747499ef4ce5760fd6acf84c987466072f376 (diff) | |
download | libpcap-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.c | 6 |
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)); |