aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--acinclude.m42
-rw-r--r--capture-pcap-util.c27
-rw-r--r--capture-wpcap.c26
3 files changed, 52 insertions, 3 deletions
diff --git a/acinclude.m4 b/acinclude.m4
index 37258ed201..ca97345c2f 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -522,7 +522,7 @@ install a newer version of the header file.])
[Define to 1 if you have the `pcap_findalldevs' function and a pcap.h that declares pcap_if_t.])
AC_CHECK_FUNCS(pcap_datalink_val_to_name pcap_datalink_name_to_val)
AC_CHECK_FUNCS(pcap_list_datalinks pcap_set_datalink pcap_lib_version)
- AC_CHECK_FUNCS(pcap_get_selectable_fd)
+ AC_CHECK_FUNCS(pcap_get_selectable_fd pcap_free_datalinks)
fi
LIBS="$ac_save_LIBS"
])
diff --git a/capture-pcap-util.c b/capture-pcap-util.c
index 129712d426..0d7024af5f 100644
--- a/capture-pcap-util.c
+++ b/capture-pcap-util.c
@@ -412,11 +412,34 @@ get_pcap_linktype_list(const char *devname, char **err_str)
linktype_list = g_list_append(linktype_list,
data_link_info);
}
- free(linktypes);
+#ifdef HAVE_PCAP_FREE_DATALINKS
+ pcap_free_datalinks(linktypes);
#else
+ /*
+ * In Windows, 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.
+ *
+ * See the mail threads starting at
+ *
+ * http://www.winpcap.org/pipermail/winpcap-users/2006-September/001421.html
+ *
+ * and
+ *
+ * http://www.winpcap.org/pipermail/winpcap-users/2008-May/002498.html
+ */
+#ifndef _WIN32
+ free(linktypes);
+#endif /* _WIN32 */
+#endif /* HAVE_PCAP_FREE_DATALINKS */
+#else /* HAVE_PCAP_LIST_DATALINKS */
data_link_info = create_data_link_info(deflt);
linktype_list = g_list_append(linktype_list, data_link_info);
-#endif
+#endif /* HAVE_PCAP_LIST_DATALINKS */
pcap_close(pch);
return linktype_list;
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)