avoid fd leak if opendir is cancelled when calloc has failed