[Winpcap-users] freeing memory allocated by pcap_stats_ex viewpcap.dll

Gianluca Varenni gianluca.varenni at cacetech.com
Mon Jun 6 15:56:22 GMT 2005


Hi.

Actually the chunk of memory returned by pcap_stats_ex should not be freed by the caller, since it's managed directly by the pcap library. Basically, it's preallocated inside the pcap_t structure; every call to pcap_stats_ex fills the array with fresh stats, and returns the same pointer to the caller.

You can see the implementation of such function in the online winpcap documentation, at

https://www.winpcap.org/docs/docs31beta4/html/Win32-Extensions_8c-source.html#l00062

Have a nice day
GV

  ----- Original Message ----- 
  From: Gal Szkolnik 
  To: winpcap-users at winpcap.org 
  Sent: Monday, June 06, 2005 3:08 AM
  Subject: [Winpcap-users] freeing memory allocated by pcap_stats_ex viewpcap.dll


  Hello.
  I've been using WinPCap for a long time now with a C# application we constructed over here (= my work place), and am very pleased with it.
   
  I have one problem which I can't fix gracefully, and was wondering if anyone can help me. 
   
  As I understand from the code, pcap_stats_ex allocates the memory for the user, and later the user is responsible to deallocate it.
  My problem is that I am accesing wpcap.dll through PInvoke and don't have access to the memory managment functions used in the pcap dll. 
   
  Another issue, is if used from another exe or dll (this time unmanaged regular C++ or C) if the compiler/libraries are different from what winpcap.dll was built with they would not be compatible when freeing memory. 
   
  I would suggest a solution: Use a free_stats function in wpcap.lib which frees the allocated buffer. The user still deallocates the structure, but does it via a function call to the dll. This ensures deallocation is done correctly. 
   
  Tell me what you think? and if you'll change the source code and add this function
   
  -- 
  Truly Yours
  Gal Szkolnik 


------------------------------------------------------------------------------


  _______________________________________________
  Winpcap-users mailing list
  Winpcap-users at winpcap.org
  https://www.winpcap.org/mailman/listinfo/winpcap-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20050606/f3ddbb43/attachment.html


More information about the Winpcap-users mailing list