aboutsummaryrefslogtreecommitdiffstats
path: root/capture-wpcap.c
diff options
context:
space:
mode:
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2008-07-04 03:33:00 +0000
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>2008-07-04 03:33:00 +0000
commit5ca5c01f053d3559d4925d5d4a88229bd514c943 (patch)
treec9fa56081cba2db8532d95df30deaee552e03d47 /capture-wpcap.c
parent77141a5d22b3f01a422d78a10119cc842467c1e8 (diff)
If we have pcap_free_datalinks(), use it. If not, then, on Windows,
just leak the list returned by pcap_list_datalinks(), as there's no guarantee that if you have a library built with one version of the MSVC++ run-time library, and it returns a pointer to allocated data, you can free that data from a program linked with another version of the MSVC++ run-time library. (This is not an issue on UN*X.) This should fix bug 2677. git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@25668 f5534014-38df-0310-8fa8-9805f1628bb7
Diffstat (limited to 'capture-wpcap.c')
-rw-r--r--capture-wpcap.c26
1 files changed, 26 insertions, 0 deletions
diff --git a/capture-wpcap.c b/capture-wpcap.c
index 66bfc3652a..90baec774b 100644
--- a/capture-wpcap.c
+++ b/capture-wpcap.c
@@ -111,6 +111,10 @@ static int (*p_pcap_list_datalinks)(pcap_t *, int **);
static int (*p_pcap_set_datalink)(pcap_t *, int);
#endif
+#ifdef HAVE_FREE_DATALINKS
+static int (*p_pcap_free_datalinks)(int *);
+#endif
+
typedef struct {
const char *name;
gpointer *ptr;
@@ -174,6 +178,9 @@ load_wpcap(void)
#ifdef HAVE_PCAP_SET_DATALINK
SYM(pcap_set_datalink, FALSE),
#endif
+#ifdef HAVE_PCAP_FREE_DATALINKS
+ SYM(pcap_free_datalinks, TRUE),
+#endif
{ NULL, NULL, FALSE }
};
@@ -503,6 +510,25 @@ pcap_list_datalinks(pcap_t *p, int **ddlt)
}
#endif
+#ifdef HAVE_PCAP_FREE_DATALINKS
+void
+pcap_free_datalinks(int *ddlt)
+{
+ g_assert(has_wpcap);
+
+ /*
+ * If we don't have pcap_free_datalinks() in WinPcap,
+ * we don't free the memory - we can't use free(), as
+ * we might not have been built with the same version
+ * of the C runtime library as WinPcap was, and, if we're
+ * not, free() isn't guaranteed to work on something
+ * allocated by WinPcap.
+ */
+ if (p_pcap_free_datalinks != NULL)
+ p_pcap_free_datalinks(ddlt);
+}
+#endif
+
#ifdef HAVE_PCAP_DATALINK_VAL_TO_NAME
const char *
pcap_datalink_val_to_name(int dlt)