diff options
author | Guy Harris <guy@alum.mit.edu> | 2008-07-04 03:33:00 +0000 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2008-07-04 03:33:00 +0000 |
commit | e82d99d2b4b86a22f37dd19481fdcbe8ca7635a8 (patch) | |
tree | c9fa56081cba2db8532d95df30deaee552e03d47 /capture-wpcap.c | |
parent | d1275537c02918305015a9128a3f4efcb19408ab (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.
svn path=/trunk/; revision=25668
Diffstat (limited to 'capture-wpcap.c')
-rw-r--r-- | capture-wpcap.c | 26 |
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) |