Error handling was silent and had leaks.
Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
/* allocate */
lf = malloc(sizeof(*lf));
- if (!lf)
+ if (!lf) {
+ fprintf(stderr, "out of memory\n");
return NULL;
+ }
/* initialize */
memset(lf, 0, sizeof(*lf));
/* open */
lf->fp = fopen(lf->path, "r");
if (!lf->fp) {
+ perror(lf->path);
free(lf);
return NULL;
}
continue;
lf = alloc_and_open(path, de->d_name);
- if (!lf)
+ if (!lf) {
+ closedir(dir);
return NULL;
+ }
/* fill in field structure */
- if (lnstat_scan_fields(lf) < 0)
+ if (lnstat_scan_fields(lf) < 0) {
+ closedir(dir);
return NULL;
+ }
/* prepend to global list */
lf->next = lnstat_files;