mirror of
https://github.com/AuxXxilium/linux_dsm_epyc7002.git
synced 2024-12-14 12:36:52 +07:00
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:
parent
578f737dd3
commit
a4d429e362
@ -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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user