]> The Tcpdump Group git mirrors - libpcap/commitdiff
Fix a memory leak found by Miklos Szeredi
authorguy <guy>
Tue, 3 Jul 2001 19:15:47 +0000 (19:15 +0000)
committerguy <guy>
Tue, 3 Jul 2001 19:15:47 +0000 (19:15 +0000)
<[email protected]> - "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.

gencode.c
grammar.y

index 9c31e8727d1f5e29bb82406c85376a8409876610..7959d344c7263182be95e33bf960dc3c836028d6 100644 (file)
--- a/gencode.c
+++ b/gencode.c
@@ -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*/
index c554cc64b87d9a9c553137151ac4599e984ed3fc..672bbed54d8d7bbb321c7044a9fb67676b63b2ec 100644 (file)
--- a/grammar.y
+++ b/grammar.y
@@ -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; }