const size_t length = scandir(path.string, &listing, filter, sort);
if (length == -1) {
+ if (listing) {
+ f_memory_delete(1, sizeof(struct dirent *), (void *) listing);
+ }
+
if (errno == ENOMEM) return F_status_set_error(F_memory_not);
return F_status_set_error(F_failure);
f_memory_delete(size, sizeof(struct dirent), (void *) listing[i]);
} // for
- f_memory_delete(1, sizeof(struct dirent *), (void **) listing);
+ f_memory_delete(1, sizeof(struct dirent *), (void *) listing);
if (F_status_is_error(status)) {
return status;
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
- // The scandir() allocates the entire struct dirent.
- struct dirent **directories = (struct dirent **) malloc(sizeof(struct dirent *));
+ struct dirent *directories[0];
memset(directories, 0, sizeof(struct dirent *));
const f_string_static_t path = macro_f_string_static_t_initialize("test", 0, 4);
{
- // The scandir() allocates the entire struct dirent.
- struct dirent **directories = (struct dirent **) malloc(sizeof(struct dirent *));
+ struct dirent *directories[1];
+ // The scandir() allocates each struct dirent.
directories[0] = (struct dirent *) malloc(sizeof(struct dirent));
memset(directories[0], 0, sizeof(struct dirent));