Discussion:
[PATCH] fts: avoid a memory leak edge case
Pádraig Brady
7 years ago
Permalink
...
Yes valgrind indicates that fts_level is uninitialized if you
fts_close() right after fts_open().
The attached should fix it up.

thanks!
Pádraig
Kamil Dudka
7 years ago
Permalink
@@ -122,9 +139,10 @@ main (void)
perror_exit (base, 6);
while ((e = fts_read (ftsp)))
needles_seen += strcmp (e->fts_name, "needle") == 0;
- fflush (stdout);
if (errno)
perror_exit ("fts_read", 7);
+ if (fts_close (ftsp) != 0)
+ perror_exit (base, 8);
/* Report an error if we did not find the needles. */
if (needles_seen != needles)
Why are you removing fflush (stdout) from the test without any explanation?

Kamil
Bruno Haible
7 years ago
Permalink
Post by Kamil Dudka
Why are you removing fflush (stdout) from the test without any explanation?
Yes, fflush(stdout) statements are extremely important if you want to
understand/debug test failures on native Windows.

Bruno
Pádraig Brady
7 years ago
Permalink
Post by Bruno Haible
Post by Kamil Dudka
Why are you removing fflush (stdout) from the test without any explanation?
Yes, fflush(stdout) statements are extremely important if you want to
understand/debug test failures on native Windows.
Oops, I wasn't aware of windows considerations.

I didn't actually see where there was any output to stdout
in this test, and I thought fflush() was therefore redundant?
More problematically could impinge on the previous fts_read() errno?

Should save the errno from fts_read?
Should I perror() any errno from fflush?

cheers,
Pádraig

Continue reading on narkive:
Loading...