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