From b20a7a0ed29c40ad50c0e43b1f3d1cf3558f492e Mon Sep 17 00:00:00 2001
From: Jianqiu Zhang <zhangjianqiu_133@yeah.net>
Date: Thu, 7 Jan 2016 16:34:17 +0800
Subject: wpcap: Fix crash on pcap_loop

Signed-off-by: Jianqiu Zhang <zhangjianqiu_133@yeah.net>
---
 dlls/wpcap/wpcap.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/dlls/wpcap/wpcap.c b/dlls/wpcap/wpcap.c
index da911c7..44e8c2a 100644
--- a/dlls/wpcap/wpcap.c
+++ b/dlls/wpcap/wpcap.c
@@ -95,7 +95,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");
 }
 
@@ -108,10 +107,14 @@ int CDECL wine_pcap_dispatch(pcap_t *p, int cnt,
     if (callback)
     {
         PCAP_HANDLER_CALLBACK *pcb;
+        int res;
+
         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);
@@ -201,10 +204,14 @@ int CDECL wine_pcap_loop(pcap_t *p, int cnt,
     if (callback)
     {
         PCAP_HANDLER_CALLBACK *pcb;
+        int res;
+
         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);
-- 
2.6.4

