1) Allocate less by not sorting the result with qsort. Instead, insert the nodes in the correct order; 2) Do not maintain the whole path in memory, but rely on openat()