diff options
author | Peter Meerwald <pmeerw@pmeerw.net> | 2012-06-25 21:13:25 (GMT) |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2012-06-30 09:12:24 (GMT) |
commit | a4d429e362d873414046c78724f3d6a7978bc2fd (patch) | |
tree | 2377440a0f19efc3fc0898b6e3edcf7aa8800b3f /drivers/staging/iio/Documentation | |
parent | 578f737dd36989121412cf947a5b534e7b8a0ac5 (diff) | |
download | linux-fsl-qoriq-a4d429e362d873414046c78724f3d6a7978bc2fd.tar.xz |
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>
Diffstat (limited to 'drivers/staging/iio/Documentation')
-rw-r--r-- | drivers/staging/iio/Documentation/iio_utils.h | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/drivers/staging/iio/Documentation/iio_utils.h b/drivers/staging/iio/Documentation/iio_utils.h index ab78859..81a6289 100644 --- a/drivers/staging/iio/Documentation/iio_utils.h +++ b/drivers/staging/iio/Documentation/iio_utils.h @@ -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; } |