PERFORCE change 134487 for review

Christian S.J. Peron csjp at FreeBSD.org
Wed Jan 30 13:51:52 PST 2008


http://perforce.freebsd.org/chv.cgi?CH=134487

Change 134487 by csjp at csjp_xor on 2008/01/30 21:51:29

	Check to see if this pcap instance was using the zerocopy buffer
	mode.  If it was, delete the mappings.  Note that p->buffer
	gets initialized to one of the mmaped regions in this case, so
	do not try and free it directly.

Affected files ...

.. //depot/projects/zcopybpf/src/contrib/libpcap/pcap.c#3 edit

Differences ...

==== //depot/projects/zcopybpf/src/contrib/libpcap/pcap.c#3 (text+ko) ====

@@ -44,6 +44,7 @@
 #include <pcap-stdinc.h>
 #else /* WIN32 */
 #include <sys/types.h>
+#include <sys/mman.h>
 #endif /* WIN32 */
 
 #include <stdio.h>
@@ -738,6 +739,24 @@
 void
 pcap_close_common(pcap_t *p)
 {
+#ifdef BIOCSETBUFMODE
+	/*
+	 * Check to see if this pcap instance was using the zerocopy buffer
+	 * mode.  If it was, delete the mappings.  Note that p->buffer
+	 * gets initialized to one of the mmaped regions in this case, so
+	 * do not try and free it directly.
+	 *
+	 * If the regular buffer mode was selected, then it is safe to free
+	 * this memory.
+	 */
+	if (p->zerocopy) {
+		if (p->zbuf1 != MAP_FAILED && p->zbuf1 != NULL)
+			munmap(p->zbuf1, p->zbufsize);
+		if (p->zbuf2 != MAP_FAILED && p->zbuf2 != NULL)
+			munmap(p->zbuf2, p->zbufsize);
+		p->buffer = NULL;
+	} else
+#endif
 	if (p->buffer != NULL)
 		free(p->buffer);
 #if !defined(WIN32) && !defined(MSDOS)


More information about the p4-projects mailing list