From: Peter Meerwald Date: Mon, 25 Jun 2012 21:13:25 +0000 (+0200) Subject: iio staging: fix potential memory/resource leaks in find_type_by_name() X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=a4d429e362d873414046c78724f3d6a7978bc2fd;p=GitHub%2Fmt8127%2Fandroid_kernel_alcatel_ttab.git iio staging: fix potential memory/resource leaks in find_type_by_name() Signed-off-by: Peter Meerwald Signed-off-by: Jonathan Cameron --- diff --git a/drivers/staging/iio/Documentation/iio_utils.h b/drivers/staging/iio/Documentation/iio_utils.h index ab788594b202..81a628975cdd 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; }