]> The Tcpdump Group git mirrors - libpcap/blobdiff - optimize.c
Add a "pcap_close_common()" routine which can be used as the close
[libpcap] / optimize.c
index 2fefbef0c6f8a6969ee0891f0bd175cb98748a2c..da7a1e4b910c974a4548a69ae02828d1a318b9fd 100644 (file)
@@ -21,8 +21,8 @@
  *  Optimization module for tcpdump intermediate representation.
  */
 #ifndef lint
-static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.73 2002-06-11 05:30:40 itojun Exp $ (LBL)";
+static const char rcsid[] _U_ =
+    "@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.77 2003-11-15 23:24:00 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -1139,7 +1139,7 @@ opt_blk(b, do_stmts)
         * already there, or if this block is a return,
         * eliminate all the statements.
         */
-       if (do_stmts && 
+       if (do_stmts &&
            ((b->out_use == 0 && aval != 0 &&b->val[A_ATOM] == aval) ||
             BPF_CLASS(b->s.code) == BPF_RET)) {
                if (b->stmts != 0) {
@@ -1842,17 +1842,23 @@ opt_init(root)
        unMarkAll();
        n = count_blocks(root);
        blocks = (struct block **)malloc(n * sizeof(*blocks));
+       if (blocks == NULL)
+               bpf_error("malloc");
        unMarkAll();
        n_blocks = 0;
        number_blks_r(root);
 
        n_edges = 2 * n_blocks;
        edges = (struct edge **)malloc(n_edges * sizeof(*edges));
+       if (edges == NULL)
+               bpf_error("malloc");
 
        /*
         * The number of levels is bounded by the number of nodes.
         */
        levels = (struct block **)malloc(n_blocks * sizeof(*levels));
+       if (levels == NULL)
+               bpf_error("malloc");
 
        edgewords = n_edges / (8 * sizeof(bpf_u_int32)) + 1;
        nodewords = n_blocks / (8 * sizeof(bpf_u_int32)) + 1;
@@ -1860,6 +1866,8 @@ opt_init(root)
        /* XXX */
        space = (bpf_u_int32 *)malloc(2 * n_blocks * nodewords * sizeof(*space)
                                 + n_edges * edgewords * sizeof(*space));
+       if (space == NULL)
+               bpf_error("malloc");
        p = space;
        all_dom_sets = p;
        for (i = 0; i < n; ++i) {
@@ -1897,6 +1905,8 @@ opt_init(root)
        maxval = 3 * max_stmts;
        vmap = (struct vmapinfo *)malloc(maxval * sizeof(*vmap));
        vnode_base = (struct valnode *)malloc(maxval * sizeof(*vnode_base));
+       if (vmap == NULL || vnode_base == NULL)
+               bpf_error("malloc");
 }
 
 /*
@@ -1945,7 +1955,7 @@ convert_code_r(p)
 
        /* generate offset[] for convenience  */
        if (slen) {
-               offset = (struct slist **)calloc(sizeof(struct slist *), slen);
+               offset = (struct slist **)calloc(slen, sizeof(struct slist *));
                if (!offset) {
                        bpf_error("not enough core");
                        /*NOTREACHED*/
@@ -2091,12 +2101,14 @@ icode_to_fcode(root, lenp)
        while (1) {
            unMarkAll();
            n = *lenp = count_stmts(root);
-    
+
            fp = (struct bpf_insn *)malloc(sizeof(*fp) * n);
+           if (fp == NULL)
+                   bpf_error("malloc");
            memset((char *)fp, 0, sizeof(*fp) * n);
            fstart = fp;
            ftail = fp + n;
-    
+
            unMarkAll();
            if (convert_code_r(root))
                break;