diff options
| author | 2001-12-17 22:29:47 +0000 | |
|---|---|---|
| committer | 2001-12-17 22:29:47 +0000 | |
| commit | 78871eb876677c1cfa6cb2a6202247a39f574ae0 (patch) | |
| tree | 700ae2d407e898e8e429b3ec9e8f7a240c082bee /lib/libpcap/gencode.c | |
| parent | sync (diff) | |
| download | wireguard-openbsd-78871eb876677c1cfa6cb2a6202247a39f574ae0.tar.xz wireguard-openbsd-78871eb876677c1cfa6cb2a6202247a39f574ae0.zip | |
fix memory leak associated with compiled BPF program, sync'd from tcpdump.org. ok itojun@
Diffstat (limited to 'lib/libpcap/gencode.c')
| -rw-r--r-- | lib/libpcap/gencode.c | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lib/libpcap/gencode.c b/lib/libpcap/gencode.c index 60eb842b4b9..9f494914ba1 100644 --- a/lib/libpcap/gencode.c +++ b/lib/libpcap/gencode.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gencode.c,v 1.13 2001/06/25 23:03:32 provos Exp $ */ +/* $OpenBSD: gencode.c,v 1.14 2001/12/17 22:29:47 dugsong Exp $ */ /* * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998 @@ -22,7 +22,7 @@ */ #ifndef lint static const char rcsid[] = - "@(#) $Header: /home/cvs/src/lib/libpcap/gencode.c,v 1.13 2001/06/25 23:03:32 provos Exp $ (LBL)"; + "@(#) $Header: /home/cvs/src/lib/libpcap/gencode.c,v 1.14 2001/12/17 22:29:47 dugsong Exp $ (LBL)"; #endif #include <sys/types.h> @@ -363,6 +363,20 @@ pcap_compile_nopcap(int snaplen_arg, int linktype_arg, } /* + * Clean up a "struct bpf_program" by freeing all the memory allocated + * in it. + */ +void +pcap_freecode(struct bpf_program *program) +{ + program->bf_len = 0; + if (program->bf_insns != NULL) { + free((char *)program->bf_insns); + program->bf_insns = NULL; + } +} + +/* * Backpatch the blocks in 'list' to 'target'. The 'sense' field indicates * which of the jt and jf fields has been resolved and which is a pointer * back to another unresolved block (or nil). At least one of the fields |
