Re: [Mingw-users] CRT lib: potential memory leakage
-----BEGIN PGP SIGNED MESSAGE-----
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)
I'm sure you realize that this is a bug in _your_ program. You did not
allocate storage for argv, (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) somehow.
You are assuming that argv is even stored in memory which originated
with a call to malloc(); that calling free(argv) 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
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)
-----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
This list observes the Etiquette found at
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: