Wireshark-dev: Re: [Wireshark-dev] Memory Leak
From: <gogrady@xxxxxxxxx>
Date: Wed, 25 Mar 2009 17:12:10 +0000
Hi Andy, Yes it is written in C++, everytime i have new, i use delete in the same function in the dll. I have a function that uses malloc for a char * to return to the dissector setting a char * variable to use in proto_tree_add_text and then i want to send it back to the dll to a function that is: void ReleaseBuffer( void * buffer ) { free(buffer); } casting the char * in the dissector call to this dll function. Greg ---- Andy Lawman <ALawman@xxxxxxxxxxx> wrote: ============= Isn't your DLL written in C++? You're not mixing new & free are you? Storage got with new must be returned with delete, new [ ] with delete [ ] but only malloc() with free(). Andy. <gogrady@xxxxxxxxx> To Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx> cc bcc Subject Re: [Wireshark-dev] Memory Leak <gogrady@xxxxxxxxx> Please respond to : Developer support list for Wireshark <wireshark-dev@xxxxxxxxxxxxx> Sent by: wireshark-dev-bounces@xxxxxxxxxxxxx 25/03/2009 14:22 Hmm, we'll this is the first time i am working with memory and am just learning all about it. In those examples they seem to allocate and free in the same function, but i cant do that. In my dll i have one function that allocates memory and passes a char * back to the dissector to set a variable with it, then i have another function that frees it in the dll (pass it the char * and free it with free((void *)variable);) but that also gives me an error, so i'm not sure how and where to free the memory. Greg ---- Gianluca Varenni <gianluca.varenni@xxxxxxxxxxxx> wrote: ============= If the memory is allocated within the DLL, it should be freed from within the DLL (i.e. you should provide a function exported by the DLL to free such memory). Allocating memory with malloc in a DLL and free'ing it from outside the DLL is bad mojo. http://msdn.microsoft.com/en-us/library/ms235460(VS.80).aspx Have a nice day GV ----- Original Message ----- From: <gogrady@xxxxxxxxx> To: <wireshark-dev@xxxxxxxxxxxxx> Sent: Tuesday, March 24, 2009 9:57 AM Subject: [Wireshark-dev] Memory Leak > Hi all, > > So in my dissector, i call a dll that allocates memory for information to > be returned back for output, but when i try and free the memory, i get an > error. I was wondering what the scope of the memory would be and where i > should free it, maybe i'm freeing it wrong. I allocate it in my dll after > if(tree) and free it at the end of the if statement. This is how i > allocate: > > char * change = (char *)malloc(string.GetLength()+1); > memset(change,0,string.GetLength()+1); > ::strncpy_s(change, string.GetLength()+1, string, string.GetLength()); > return change; > > and i just want to use free(variable); but i get: > > HEAP[wireshark.exe]: Invalid Address specified to RtlFreeHeap( 027E0000, > 05E8F998 ) > Windows has triggered a breakpoint in wireshark.exe. > > This may be due to a corruption of the heap, which indicates a bug in > wireshark.exe or any of the DLLs it has loaded. > > This may also be due to the user pressing F12 while wireshark.exe has > focus. > > The output window may have more diagnostic information. > > pointing to the: > ::strncpy_s(change, string.GetLength()+1, string, string.GetLength()); > line > > Thanks for any help, > > Greg > ___________________________________________________________________________ > Sent via: Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx> > Archives: http://www.wireshark.org/lists/wireshark-dev > Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev > mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe ___________________________________________________________________________ Sent via: Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx> Archives: http://www.wireshark.org/lists/wireshark-dev Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe ___________________________________________________________________________ Sent via: Wireshark-dev mailing list <wireshark-dev@xxxxxxxxxxxxx> Archives: http://www.wireshark.org/lists/wireshark-dev Unsubscribe: https://wireshark.org/mailman/options/wireshark-dev mailto:wireshark-dev-request@xxxxxxxxxxxxx?subject=unsubscribe IMPORTANT - CONFIDENTIALITY NOTICE - This e-mail is intended only for the use of the addressee/s above. It may contain information which is privileged, confidential or otherwise protected from disclosure under applicable laws. If the reader of this transmission is not the intended recipient, you are hereby notified that any dissemination, printing, distribution, copying, disclosure or the taking of any action in reliance on the contents of this information is strictly prohibited. If you have received this transmission in error, please immediately notify us by reply e-mail or using the address below and delete the message and any attachments from your system. Amadeus Services Ltd, World Business Centre 3, 1208 Newall Road, Hounslow, Middlesex, TW6 2TA, Registered number 4040059
- References:
- Re: [Wireshark-dev] Memory Leak
- From: Andy Lawman
- Re: [Wireshark-dev] Memory Leak
- Prev by Date: Re: [Wireshark-dev] Memory Leak
- Next by Date: [Wireshark-dev] Problem with 1.1.3 sources - native-nmake
- Previous by thread: Re: [Wireshark-dev] Memory Leak
- Next by thread: [Wireshark-dev] HTTP reassembly?
- Index(es):