if(0 != errno) {
reply_with_perror ("readdir: /sys/block");
free_stringslen(r, size);
+ closedir (dir);
return NULL;
}
return NULL;
}
- /* Sort the devices */
- sort_strings (r, size);
+ /* Sort the devices. Note that r might be NULL if there are no devices. */
+ if (r != NULL)
+ sort_strings (r, size);
/* NULL terminate the list */
if (add_string (&r, &size, &alloc, NULL) == -1) {
if(0 != errno) {
reply_with_perror ("readdir: %s", devdir);
free_stringslen(*r, *size);
+ closedir (dir);
return -1;
}