diff options
author | xujing <xujing125@huawei.com> | 2022-11-28 11:19:20 +0800 |
---|---|---|
committer | Michal Domonkos <mdomonko@redhat.com> | 2023-03-13 15:32:25 +0100 |
commit | d336ec8303667b2edc361439aa1f4d7dc374b413 (patch) | |
tree | bbc95235c2e67bbb8e9b27f57638a7587b775e3b | |
parent | d1d6eb987f9e8294ecd5c166f71eea16a048403e (diff) | |
download | rpm-d336ec8303667b2edc361439aa1f4d7dc374b413.tar.gz |
Fix fileleak and memleak in rpmInstall
The "*eiu->fnp" from "eiu->pkgURL[eiu->pkgx]" which is alloced. when
Fopen or rpmReadPackageFile fails in tryReadHeader, "*eiu->fnp" is
set to NULL but not freed. In addition, if "eiu->pkgState[eiu->pkgx]"
is set, the file is leaked too. Fix it.
Only resource free is added, no other logic change.
(cherry picked from commit f0f983b145583eeed618cf3cbc5d39bedd8af5a5)
-rw-r--r-- | lib/rpminstall.c | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/lib/rpminstall.c b/lib/rpminstall.c index 3a1b87d35..901964f8c 100644 --- a/lib/rpminstall.c +++ b/lib/rpminstall.c @@ -355,7 +355,6 @@ static int tryReadHeader(rpmts ts, struct rpmEIU * eiu, Header * hdrp) fd = NULL; } eiu->numFailed++; - *eiu->fnp = NULL; return RPMRC_FAIL; } @@ -371,7 +370,6 @@ static int tryReadHeader(rpmts ts, struct rpmEIU * eiu, Header * hdrp) if (eiu->rpmrc == RPMRC_FAIL) { rpmlog(RPMLOG_ERR, _("%s cannot be installed\n"), *eiu->fnp); eiu->numFailed++; - *eiu->fnp = NULL; } return RPMRC_OK; @@ -556,8 +554,12 @@ restart: rpmlog(RPMLOG_DEBUG, "============== %s\n", *eiu->fnp); (void) urlPath(*eiu->fnp, &fileName); - if (tryReadHeader(ts, eiu, &h) == RPMRC_FAIL) + if (tryReadHeader(ts, eiu, &h) == RPMRC_FAIL) { + if (eiu->pkgState[eiu->fnp - eiu->pkgURL] == 1) + (void) unlink(*eiu->fnp); + *eiu->fnp = _free(*eiu->fnp); continue; + } if (eiu->rpmrc == RPMRC_NOTFOUND) { rc = tryReadManifest(eiu); @@ -566,6 +568,10 @@ restart: headerFree(h); goto restart; } + } else if (eiu->rpmrc == RPMRC_FAIL) { + if (eiu->pkgState[eiu->fnp - eiu->pkgURL] == 1) + (void) unlink(*eiu->fnp); + *eiu->fnp = _free(*eiu->fnp); } if (headerIsSource(h)) { |