summaryrefslogtreecommitdiff
path: root/src/io.c
diff options
context:
space:
mode:
authorTimo Teräs <timo.teras@iki.fi>2014-10-07 17:03:51 +0300
committerTimo Teräs <timo.teras@iki.fi>2014-10-07 17:04:38 +0300
commit1bbca16333bb655b73bd80fc40d072fc697e4650 (patch)
tree01d62ed4910e81ea195e980c6cdf7d1cc69fab62 /src/io.c
parent09e48d8f06bfb924b80ce3e95c281524c4891828 (diff)
downloadapk-tools-1bbca16333bb655b73bd80fc40d072fc697e4650.tar.gz
apk-tools-1bbca16333bb655b73bd80fc40d072fc697e4650.tar.bz2
apk-tools-1bbca16333bb655b73bd80fc40d072fc697e4650.tar.xz
apk-tools-1bbca16333bb655b73bd80fc40d072fc697e4650.zip
io: fix few error path leaks
Diffstat (limited to 'src/io.c')
-rw-r--r--src/io.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/src/io.c b/src/io.c
index 5ea5e4f..c713107 100644
--- a/src/io.c
+++ b/src/io.c
@@ -427,14 +427,19 @@ struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const ch
struct apk_tee_bstream *tbs;
int fd;
+ if (!from) return NULL;
+
fd = openat(atfd, to, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
- if (fd < 0)
+ if (fd < 0) {
+ from->close(from, NULL);
return NULL;
+ }
tbs = malloc(sizeof(struct apk_tee_bstream));
- if (tbs == NULL) {
+ if (!tbs) {
close(fd);
+ from->close(from, NULL);
return NULL;
}