Tim Ruehsen <[email protected]> writes:
> 5. It is just a matter of good coding style.
I'll consider adding those free calls (motivated by the "good coding
style" argument, with no comment about static analyzers).
> Are you going to say "ahhh, it is the main function - I don't need to
> call free() here." ?
Yes, I'd definitely say that. And I would expect a static analyzer to do
the same (either by default, or with some reasonable command line flag).
I have a hard time to view this as a memory leak or a problem at all.
I'm a bit curious on how you and the analyzer reason about the
following three examples.
1.
int
main (int argv, char **argv)
{
char *p = malloc (4711);
return 0;
}
2.
int
main (int argv, char **argv)
{
char *p = malloc (4711);
exit (0);
}
3.
static void
foo (void)
{
fprintf (stderr, "Failed!\n");
exit (1);
}
int
main (int argv, char **argv)
{
char *p = malloc (4711);
foo ();
free (p); /* Let's keep the main function itself "clean" */
return 0;
}
Is there any good reason to say that that in one of these cases, it's a
memory leak, while in some of the other cases, it is not?
To arrange for proper freeing before program exit in case (3) (or more
complex real programs with that pattern), one would have to add an
atexit call in main and potentially also in lots of other functions
doing allocation. That would really clutter the code, for very little
benefit.
Regards,
/Niels
--
Niels Möller. PGP-encrypted email is preferred. Keyid C0B98E26.
Internet email is subject to wholesale government surveillance.
_______________________________________________
nettle-bugs mailing list
[email protected]
http://lists.lysator.liu.se/mailman/listinfo/nettle-bugs