On 11.02.2016 09:55, Jianqiu Zhang wrote:
> From 359272d74611e2c4a6ab1e3eb452cb277043b6d2 Mon Sep 17 00:00:00 2001
> From: Jianqiu Zhang <zhangjianqiu_133(a)yeah.net>
> Date: Tue, 5 Jan 2016 09:12:42 +0800
> Subject: [PATCH 2/2] wpcap: Fix crash on pcap_loop
>
> Signed-off-by: Jianqiu Zhang <zhangjianqiu_133(a)yeah.net>
> ---
> dlls/wpcap/wpcap.c | 11 ++++++++---
> 1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/dlls/wpcap/wpcap.c b/dlls/wpcap/wpcap.c
> index e03e18e..3b0f618 100644
> --- a/dlls/wpcap/wpcap.c
> +++ b/dlls/wpcap/wpcap.c
> @@ -99,7 +99,6 @@ static void pcap_handler_callback(u_char *user_data, const struct pcap_pkthdr *h
> TRACE("(%p %p %p)\n", user_data, h, p);
> pcb = (PCAP_HANDLER_CALLBACK *)user_data;
> pcb->pfn_cb(pcb->user_data, h, p);
> - HeapFree(GetProcessHeap(), 0, pcb);
> TRACE("Callback COMPLETED\n");
> }
>
> @@ -111,11 +110,14 @@ int CDECL wine_pcap_dispatch(pcap_t *p, int cnt,
>
> if (callback)
> {
> + int res = 0;
You can remove the initialization here. In fact some analyzers will warn about
double-initialization when you do that although its not really necessary.
> PCAP_HANDLER_CALLBACK *pcb;
> pcb = HeapAlloc(GetProcessHeap(), 0, sizeof(PCAP_HANDLER_CALLBACK));
> pcb->pfn_cb = callback;
> pcb->user_data = user;
> - return pcap_dispatch(p, cnt, pcap_handler_callback, (unsigned char*)pcb);
> + res = pcap_dispatch(p, cnt, pcap_handler_callback, (unsigned char *)pcb);
> + HeapFree(GetProcessHeap(), 0, pcb);
> + return res;
> }
>
> return pcap_dispatch(p, cnt, NULL, user);
> @@ -204,11 +206,14 @@ int CDECL wine_pcap_loop(pcap_t *p, int cnt,
>
> if (callback)
> {
> + int res = 0;
Same here.
> PCAP_HANDLER_CALLBACK *pcb;
> pcb = HeapAlloc(GetProcessHeap(), 0, sizeof(PCAP_HANDLER_CALLBACK));
> pcb->pfn_cb = callback;
> pcb->user_data = user;
> - return pcap_loop(p, cnt, pcap_handler_callback, (unsigned char*)pcb);
> + res = pcap_loop(p, cnt, pcap_handler_callback, (unsigned char *)pcb);
> + HeapFree(GetProcessHeap(), 0, pcb);
> + return res;
> }
>
> return pcap_loop(p, cnt, NULL, user);
>
>
>
>