[PATCH 11/15] udpkg: fix fd leaks on error pathes and a unbalanced close
fds were leaking in dpkg_copyfile().
Signed-off-by: maximilian attems <max@stro.at>
---
packages/udpkg/udpkg.c | 9 ++++++++-
1 files changed, 8 insertions(+), 1 deletions(-)
diff --git a/packages/udpkg/udpkg.c b/packages/udpkg/udpkg.c
index 4bccaec..7306736 100644
--- a/packages/udpkg/udpkg.c
+++ b/packages/udpkg/udpkg.c
@@ -59,11 +59,18 @@ static int dpkg_copyfile(const char *src, const char *dest)
if ((infd = open(src, O_RDONLY)) < 0)
return -1;
if ((outfd = open(dest, O_WRONLY|O_CREAT|O_TRUNC, srcStat.st_mode)) < 0)
+ {
+ close(infd)
return -1;
+ }
while ((r = read(infd, buf, sizeof(buf))) > 0)
{
if (write(outfd, buf, r) < 0)
+ {
+ close(infd);
+ close(outfd);
return -1;
+ }
}
close(outfd);
close(infd);
@@ -235,7 +242,7 @@ static int dpkg_dounpack(struct package_t *pkg)
}
fputs(p, outfp);
}
- fclose(infp);
+ pclose(infp);
fclose(outfp);
#endif
--
1.7.2.3
Reply to: