Web lists-archives.com

Re: [Mingw-users] CRT lib: potential memory leakage




> From: "Jannick" <thirdedition@xxxxxxx>
> Date: Fri, 5 May 2017 14:33:02 +0200
> 
> it appears that the CRT lib produces some memory leakage: The small program compiled with mingw32-gcc
> (5.3.0)
> 
> #include <stdlib.h>
> 
> int main (int argc, char** argv)
> 
> {
> 
> free(argv[0]);
> 
> return 0;
> 
> } 
> 
> runs through like a charm which is suggesting that the CRT lib’s terminating clean-up work misses the exe
> path (argv[0]) somehow. 

First, what is the purpose of freeing memory just before the program
exits?  That memory will be freed by the OS anyway.

And second, the argv array is not allocated by the MinGW runtime, it
is allocated by MSVCRT.DLL, the Windows CRT shared library.  Since we
have no idea how it is allocated, calling 'free' on it in your program
is a bad idea, because you cannot be sure it was allocated by a call
to the same 'malloc' version that corresponds to the 'free' you want
to use.

IOW: don't do that!

------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
MinGW-users mailing list
MinGW-users@xxxxxxxxxxxxxxxxxxxxx

This list observes the Etiquette found at 
http://www.mingw.org/Mailing_Lists.
We ask that you be polite and do the same.  Disregard for the list etiquette may cause your account to be moderated.

_______________________________________________
You may change your MinGW Account Options or unsubscribe at:
https://lists.sourceforge.net/lists/listinfo/mingw-users
Also: mailto:mingw-users-request@xxxxxxxxxxxxxxxxxxxxx?subject=unsubscribe