Web lists-archives.com

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




-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 05/05/17 13:33, Jannick wrote:
> it appears that the CRT lib produces some memory leakage:

- From a pedantically theoretical perspective, perhaps; from a practical 
perspective, no, it does not.

> The small program compiled with mingw32-gcc (5.3.0)
> 
>   #include <stdlib.h>
> 
>   int main (int argc, char** argv)
>   {
>     free(argv[0]);

I'm sure you realize that this is a bug in _your_ program.  You did not 
allocate storage for argv[0], (nor indeed for any of argv); by calling 
free() here, you introduce undefined behaviour.

>     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.

You are assuming that argv[0] is even stored in memory which originated 
with a call to malloc(); that calling free(argv[0]) didn't immediately 
crash your program suggests that you were lucky in that assumption.
Even so, why would a terminating process bother to release individual 
heap fragments, when the entire heap allocation is about to be released 
anyway?  Even if it did devote unnecessary processing resource to this 
task, why do you assume that you would necessarily be alerted to the 
attempted free() of an already freed heap fragment?  This is undefined 
behaviour, so could have _any_ outcome, from being silently ignored, 
through crashing the (terminating) process, to wiping your hard disk,
frying your motherboard, killing your cat, or blowing up your domicile.

> I am wondering if this is intended or am I far off here?

You are imagining ramifications when, for all practical purposes, none 
arise.

- -- 
Regards,
Keith.

Public key available from keys.gnupg.net
Key fingerprint: C19E C018 1547 DE50 E1D4 8F53 C0AD 36C6 347E 5A3F
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.20 (GNU/Linux)

iQIcBAEBAgAGBQJZDH65AAoJEMCtNsY0flo/owkP+gNpdEoUh/v1jM5QZkGqSKrH
xX6hLlC66UF9WXzIV812/cp5T/ulMsK4/m+szi/7OWbmN1e0cqDT3dxL/oldmRMg
m3T9Bol26g2pFkEAhCpM2mUCC9d6T1eHA+2bN7JrhqvCOdz/MPwE1/vUjYLIGuYY
To/WdpHsKN6AdmNHKE6XvDudBPB/3oQsS9FYNvTfLAHG8iPwByn+XyWqLBsMk2TF
hTuCzL/raOxfaemqUuOdPNs0PTc8ffQgS5dzMUUTwgRoZAqTIGqDi96ZwAun3oi7
zjUt4UPK2JbDRuaZfUGJCJmpOJRIyJek+1e2lshn1mYLlNVz74sNDXjQk2Yiw4K4
qAjcidKgtmDO3ygjtnAqLRTQE1UYlq+56M5rXKRpsJPoq9TXZJBWdYzNzrOq36GE
zi6eyqoITErj5d4hJ/XC2XV0YZB+kC+MBxgGqGJbm9j/OKQdt5Sn2X5a0S7oq+zO
8Ry/C3rup6hWnU6N4vW6/O2s9OpY2aP1PapE++tPkq0U/5O48iPrY1i7vq+LnfMT
4TYnQkc6gmkOCefj9HGg2ybsoMEOW04QexLykPy56VHJzoVeeyJM71u6jk6vE2EC
qhk9vdJnDkn0xTl0cSPA70JySq99JL5Ok+HvkxnlbmzTW27eZihc+oVMjKOMlHOI
q4fZjUykRAcSA4WCXU59
=ov9s
-----END PGP SIGNATURE-----

------------------------------------------------------------------------------
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