io: fix few error path leaks

cute-signatures
Timo Teräs 2014-10-07 17:03:51 +03:00
parent 09e48d8f06
commit 1bbca16333
2 changed files with 9 additions and 6 deletions

View File

@ -149,12 +149,10 @@ struct apk_istream *apk_bstream_gunzip_mpart(struct apk_bstream *bs,
{ {
struct apk_gzip_istream *gis; struct apk_gzip_istream *gis;
if (bs == NULL) if (!bs) return NULL;
return NULL;
gis = malloc(sizeof(struct apk_gzip_istream)); gis = malloc(sizeof(struct apk_gzip_istream));
if (gis == NULL) if (!gis) goto err;
goto err;
*gis = (struct apk_gzip_istream) { *gis = (struct apk_gzip_istream) {
.is.read = gzi_read, .is.read = gzi_read,

View File

@ -427,14 +427,19 @@ struct apk_bstream *apk_bstream_tee(struct apk_bstream *from, int atfd, const ch
struct apk_tee_bstream *tbs; struct apk_tee_bstream *tbs;
int fd; int fd;
if (!from) return NULL;
fd = openat(atfd, to, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC, fd = openat(atfd, to, O_CREAT | O_RDWR | O_TRUNC | O_CLOEXEC,
S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH);
if (fd < 0) if (fd < 0) {
from->close(from, NULL);
return NULL; return NULL;
}
tbs = malloc(sizeof(struct apk_tee_bstream)); tbs = malloc(sizeof(struct apk_tee_bstream));
if (tbs == NULL) { if (!tbs) {
close(fd); close(fd);
from->close(from, NULL);
return NULL; return NULL;
} }