iio staging: fix potential memory/resource leaks in find_type_by_name()

Signed-off-by: Peter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
This commit is contained in:
Peter Meerwald 2012-06-25 23:13:25 +02:00 committed by Jonathan Cameron
parent 578f737dd3
commit a4d429e362

View File

@ -472,23 +472,30 @@ inline int find_type_by_name(const char *name, const char *type)
+ strlen(type)
+ numstrlen
+ 6);
if (filename == NULL)
if (filename == NULL) {
closedir(dp);
return -ENOMEM;
}
sprintf(filename, "%s%s%d/name",
iio_dir,
type,
number);
nameFile = fopen(filename, "r");
if (!nameFile)
if (!nameFile) {
free(filename);
continue;
}
free(filename);
fscanf(nameFile, "%s", thisname);
if (strcmp(name, thisname) == 0)
return number;
fclose(nameFile);
if (strcmp(name, thisname) == 0) {
closedir(dp);
return number;
}
}
}
}
closedir(dp);
return -ENODEV;
}