Bug 231517 - fts: causes error in valgrind
Summary: fts: causes error in valgrind
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 11.2-STABLE
Hardware: Any Any
: --- Affects Only Me
Assignee: freebsd-bugs (Nobody)
Depends on:
Reported: 2018-09-20 14:38 UTC by Nikola Kolev
Modified: 2018-09-20 15:43 UTC (History)
1 user (show)

See Also:


Note You need to log in before you can comment on or make changes to this bug.
Description Nikola Kolev 2018-09-20 14:38:38 UTC

Calling 'fts_close' immediately after 'fts_open' causes error in valgrind:

$ valgrind --track-origins=yes --tool=memcheck --leak-check=yes --show-reachable=yes ./ftstest
==76510== Memcheck, a memory error detector
==76510== Copyright (C) 2002-2013, and GNU GPL'd, by Julian Seward et al.
==76510== Using Valgrind-3.10.1 and LibVEX; rerun with -h for copyright info
==76510== Command: ./ftstest
==76510== Conditional jump or move depends on uninitialised value(s)
==76510==    at 0x4EA2297: fts_close (in /lib/libc.so.7)
==76510==    by 0x4008D9: main (in /root/fts/ftstest)
==76510==  Uninitialised value was created by a heap allocation
==76510==    at 0x4C245B1: malloc (in /usr/local/lib/valgrind/vgpreload_memcheck-amd64-freebsd.so)
==76510==    by 0x4EA1F01: fts_open (in /lib/libc.so.7)
==76510==    by 0x40089E: main (in /root/fts/ftstest)
==76510== HEAP SUMMARY:
==76510==     in use at exit: 0 bytes in 0 blocks
==76510==   total heap usage: 5 allocs, 5 frees, 2,647 bytes allocated
==76510== All heap blocks were freed -- no leaks are possible
==76510== For counts of detected and suppressed errors, rerun with: -v
==76510== ERROR SUMMARY: 1 errors from 1 contexts (suppressed: 0 from 0)


#include <fts.h>
#include <stdio.h>
#include <sys/stat.h>

main(void) {
	FTS *fts;
	char *path = "/etc";
	char * const path_argv[] = { path, NULL };

	if ((fts = fts_open(path_argv, FTS_LOGICAL, NULL)) == NULL) {
		printf("fts_open error: %s\n", path);
		return (1);
	return (0);

If 'fts_read' is called before 'fts_close' no complaints from vagrind.

+	while ((e = fts_read(fts)) != NULL) {
+		printf("name: %s, mtime: %ld\n", e->fts_name, e->fts_statp->st_mtime);
+	}

I don't know if its related but I found same issue in GNU maillist: