Commit a4d429e3 authored by Peter Meerwald's avatar Peter Meerwald Committed by Jonathan Cameron

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

Signed-off-by: default avatarPeter Meerwald <pmeerw@pmeerw.net>
Signed-off-by: default avatarJonathan Cameron <jic23@kernel.org>
parent 578f737d
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment