dect
/
libpcap
Archived
13
0
Fork 0

Fix a memory leak found by Miklos Szeredi

<Miklos.Szeredi@eth.ericsson.se> - "pcap_ether_aton()" allocates memory
for the MAC address, but we don't free it when we're done with it.

Code inspection revealed that there's a similar problem with
"pcap_ether_hostton()"; fix that as well.
This commit is contained in:
guy 2001-07-03 19:15:47 +00:00
parent db2a1d1e5e
commit ca3fec5964
2 changed files with 32 additions and 8 deletions

View File

@ -21,7 +21,7 @@
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.156 2001-06-20 07:12:38 guy Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.157 2001-07-03 19:15:47 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -2922,21 +2922,27 @@ gen_scode(name, q)
if (eaddr == NULL)
bpf_error(
"unknown ether host '%s'", name);
return gen_ehostop(eaddr, dir);
b = gen_ehostop(eaddr, dir);
free(eaddr);
return b;
case DLT_FDDI:
eaddr = pcap_ether_hostton(name);
if (eaddr == NULL)
bpf_error(
"unknown FDDI host '%s'", name);
return gen_fhostop(eaddr, dir);
b = gen_fhostop(eaddr, dir);
free(eaddr);
return b;
case DLT_IEEE802:
eaddr = pcap_ether_hostton(name);
if (eaddr == NULL)
bpf_error(
"unknown token ring host '%s'", name);
return gen_thostop(eaddr, dir);
b = gen_thostop(eaddr, dir);
free(eaddr);
return b;
default:
bpf_error(
@ -3070,7 +3076,9 @@ gen_scode(name, q)
alist = pcap_nametoaddr(name);
if (alist == NULL || *alist == NULL)
bpf_error("unknown host '%s'", name);
return gen_gateway(eaddr, alist, proto, dir);
b = gen_gateway(eaddr, alist, proto, dir);
free(eaddr);
return b;
#else
bpf_error("'gateway' not supported in this configuration");
#endif /*INET6*/

View File

@ -22,7 +22,7 @@
*/
#ifndef lint
static const char rcsid[] =
"@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.70 2001-05-10 14:48:03 fenner Exp $ (LBL)";
"@(#) $Header: /tcpdump/master/libpcap/grammar.y,v 1.71 2001-07-03 19:15:48 guy Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
@ -188,8 +188,24 @@ nid: ID { $$.b = gen_scode($1, $$.q = $<blk>0.q); }
"in this configuration");
#endif /*INET6*/
}
| EID { $$.b = gen_ecode($1, $$.q = $<blk>0.q); }
| AID { $$.b = gen_acode($1, $$.q = $<blk>0.q); }
| EID {
$$.b = gen_ecode($1, $$.q = $<blk>0.q);
/*
* $1 was allocated by "pcap_ether_aton()",
* so we must free it now that we're done
* with it.
*/
free($1);
}
| AID {
$$.b = gen_acode($1, $$.q = $<blk>0.q);
/*
* $1 was allocated by "pcap_ether_aton()",
* so we must free it now that we're done
* with it.
*/
free($1);
}
| not id { gen_not($2.b); $$ = $2; }
;
not: '!' { $$ = $<blk>0; }