!203 backport patches from upstream to fix resource leak
From: @xujing99 Reviewed-by: @licunlong Signed-off-by: @licunlong
This commit is contained in:
commit
0b4c6a3866
26
backport-Fix-BANames-leak-in-handlePreambleTag.patch
Normal file
26
backport-Fix-BANames-leak-in-handlePreambleTag.patch
Normal file
@ -0,0 +1,26 @@
|
||||
From 7fcdfd3b40f69af6a1d4980683859eef05f39b4e Mon Sep 17 00:00:00 2001
|
||||
From: xujing <xujing125@huawei.com>
|
||||
Date: Fri, 25 Nov 2022 16:48:34 +0800
|
||||
Subject: [PATCH 1/5] Fix BANames leak in handlePreambleTag
|
||||
|
||||
The "BANames" is alloced from popParseArgvString but not freed
|
||||
when spec->packages != pkg. Fix it.
|
||||
---
|
||||
build/parsePreamble.c | 1 +
|
||||
1 file changed, 1 insertion(+)
|
||||
|
||||
diff --git a/build/parsePreamble.c b/build/parsePreamble.c
|
||||
index 119551cf6..c4d137cf7 100644
|
||||
--- a/build/parsePreamble.c
|
||||
+++ b/build/parsePreamble.c
|
||||
@@ -961,6 +961,7 @@ static rpmRC handlePreambleTag(rpmSpec spec, Package pkg, rpmTagVal tag,
|
||||
BANames = _free(BANames);
|
||||
goto exit;
|
||||
}
|
||||
+ BANames = _free(BANames);
|
||||
headerPutString(pkg->header, RPMTAG_ARCH, "noarch");
|
||||
}
|
||||
if (!BACount)
|
||||
--
|
||||
2.27.0
|
||||
|
||||
28
backport-Fix-elf-leak-in-getElfColor.patch
Normal file
28
backport-Fix-elf-leak-in-getElfColor.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 01196e00beefc2ba6f7f0787350c5dd76891829a Mon Sep 17 00:00:00 2001
|
||||
From: xujing <xujing125@huawei.com>
|
||||
Date: Fri, 25 Nov 2022 17:11:22 +0800
|
||||
Subject: [PATCH 3/5] Fix elf leak in getElfColor
|
||||
|
||||
The "elf" is leaked in getElfColor when gelf_getehdr return fail.
|
||||
---
|
||||
build/rpmfc.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/build/rpmfc.c b/build/rpmfc.c
|
||||
index d35c148b9..06205469c 100644
|
||||
--- a/build/rpmfc.c
|
||||
+++ b/build/rpmfc.c
|
||||
@@ -1145,8 +1145,9 @@ static uint32_t getElfColor(const char *fn)
|
||||
color = RPMFC_ELF32;
|
||||
break;
|
||||
}
|
||||
- elf_end(elf);
|
||||
}
|
||||
+ if (elf)
|
||||
+ elf_end(elf);
|
||||
close(fd);
|
||||
}
|
||||
#endif
|
||||
--
|
||||
2.27.0
|
||||
|
||||
63
backport-Fix-fileleak-and-memleak-in-rpmInstall.patch
Normal file
63
backport-Fix-fileleak-and-memleak-in-rpmInstall.patch
Normal file
@ -0,0 +1,63 @@
|
||||
From f0f983b145583eeed618cf3cbc5d39bedd8af5a5 Mon Sep 17 00:00:00 2001
|
||||
From: xujing <xujing125@huawei.com>
|
||||
Date: Mon, 28 Nov 2022 11:19:20 +0800
|
||||
Subject: [PATCH 2/3] 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.
|
||||
---
|
||||
lib/rpminstall.c | 12 +++++++++---
|
||||
1 file changed, 9 insertions(+), 3 deletions(-)
|
||||
|
||||
diff --git a/lib/rpminstall.c b/lib/rpminstall.c
|
||||
index b392cf1c3..90474fabf 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;
|
||||
@@ -554,8 +552,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);
|
||||
@@ -564,6 +566,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)) {
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
From af81c95114bc2c01f005f15f17646a5188b5855d Mon Sep 17 00:00:00 2001
|
||||
From: xujing <xujing125@huawei.com>
|
||||
Date: Mon, 28 Nov 2022 11:34:24 +0800
|
||||
Subject: [PATCH 3/3] Fix fileleak when urlGetFile fails in rpmInstall
|
||||
|
||||
The "tfn" is created by calling rpmMkTempFile but not unlinked when
|
||||
urlGetFile fails in rpmInstall. Fix it.
|
||||
---
|
||||
lib/rpminstall.c | 5 ++++-
|
||||
1 file changed, 4 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/rpminstall.c b/lib/rpminstall.c
|
||||
index 90474fabf..c89ca30b5 100644
|
||||
--- a/lib/rpminstall.c
|
||||
+++ b/lib/rpminstall.c
|
||||
@@ -520,7 +520,10 @@ restart:
|
||||
_("skipping %s - transfer failed\n"), fileURL);
|
||||
eiu->numFailed++;
|
||||
eiu->pkgURL[eiu->pkgx] = NULL;
|
||||
- tfn = _free(tfn);
|
||||
+ if (tfn) {
|
||||
+ (void) unlink(tfn);
|
||||
+ tfn = _free(tfn);
|
||||
+ }
|
||||
break;
|
||||
}
|
||||
eiu->pkgState[eiu->pkgx] = 1;
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
From 688c4ad34d197055eb8f58fb4e45065af881598c Mon Sep 17 00:00:00 2001
|
||||
From: xujing <xujing125@huawei.com>
|
||||
Date: Mon, 28 Nov 2022 11:10:19 +0800
|
||||
Subject: [PATCH 1/3] Fix memleak when fsmRename failed in fsmCommit
|
||||
|
||||
The "dest" is alloced in fsmFsPath but not freed when fsmRename failed
|
||||
in fsmCommit. Fix it.
|
||||
---
|
||||
lib/fsm.c | 3 ++-
|
||||
1 file changed, 2 insertions(+), 1 deletion(-)
|
||||
|
||||
diff --git a/lib/fsm.c b/lib/fsm.c
|
||||
index 7987abbc9..e38155df7 100644
|
||||
--- a/lib/fsm.c
|
||||
+++ b/lib/fsm.c
|
||||
@@ -782,7 +782,8 @@ static int fsmCommit(int dirfd, char **path, rpmfi fi, rpmFileAction action, con
|
||||
}
|
||||
free(*path);
|
||||
*path = dest;
|
||||
- }
|
||||
+ } else
|
||||
+ free(dest);
|
||||
}
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
From 3b0b9d491f5828a40c15b76b4a19ca00006cf81e Mon Sep 17 00:00:00 2001
|
||||
From: xujing <xujing125@huawei.com>
|
||||
Date: Mon, 28 Nov 2022 11:02:47 +0800
|
||||
Subject: [PATCH 5/5] Fix memleak when running %generate_buildrequires
|
||||
|
||||
The "output[i]" is alloced in argvSplit but not freed when running
|
||||
%generate_buildrequires. Fix it.
|
||||
---
|
||||
build/build.c | 2 +-
|
||||
1 file changed, 1 insertion(+), 1 deletion(-)
|
||||
|
||||
diff --git a/build/build.c b/build/build.c
|
||||
index 4437f6c9c..34e01d5be 100644
|
||||
--- a/build/build.c
|
||||
+++ b/build/build.c
|
||||
@@ -279,7 +279,7 @@ static int doBuildRequires(rpmSpec spec, int test)
|
||||
|
||||
exit:
|
||||
freeStringBuf(sb_stdout);
|
||||
- free(output);
|
||||
+ argvFree(output);
|
||||
return rc;
|
||||
}
|
||||
|
||||
--
|
||||
2.27.0
|
||||
|
||||
35
backport-Fix-prog-leak-in-parseScript.patch
Normal file
35
backport-Fix-prog-leak-in-parseScript.patch
Normal file
@ -0,0 +1,35 @@
|
||||
From c013821c0c9350b67d9f9a02848e1a7f87fa180b Mon Sep 17 00:00:00 2001
|
||||
From: xujing <xujing125@huawei.com>
|
||||
Date: Fri, 25 Nov 2022 17:04:11 +0800
|
||||
Subject: [PATCH 2/5] Fix prog leak in parseScript
|
||||
|
||||
The "prog" will be alloced when using "-p" options, which cause src
|
||||
"proc" leak. Add "origproc" to point to src "proc" to fix it.
|
||||
---
|
||||
build/parseScript.c | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/build/parseScript.c b/build/parseScript.c
|
||||
index df7919238..f8b693ac6 100644
|
||||
--- a/build/parseScript.c
|
||||
+++ b/build/parseScript.c
|
||||
@@ -102,6 +102,7 @@ int parseScript(rpmSpec spec, int parsePart)
|
||||
poptContext optCon = NULL;
|
||||
char *name = NULL;
|
||||
char *prog = xstrdup("/bin/sh");
|
||||
+ char *origprog = prog;
|
||||
char *file = NULL;
|
||||
int priority = 1000000;
|
||||
struct poptOption optionsTable[] = {
|
||||
@@ -482,6 +483,8 @@ exit:
|
||||
free(reqargs);
|
||||
freeStringBuf(sb);
|
||||
free(progArgv);
|
||||
+ if (origprog != prog)
|
||||
+ free(origprog);
|
||||
free(prog);
|
||||
free(name);
|
||||
free(file);
|
||||
--
|
||||
2.27.0
|
||||
|
||||
28
backport-Fix-sbp-leak-when-running-rpmbuild-with-quiet.patch
Normal file
28
backport-Fix-sbp-leak-when-running-rpmbuild-with-quiet.patch
Normal file
@ -0,0 +1,28 @@
|
||||
From 6130bd31038ff17a03fcac6ec7e41ac744163dde Mon Sep 17 00:00:00 2001
|
||||
From: xujing <xujing125@huawei.com>
|
||||
Date: Sat, 26 Nov 2022 11:39:48 +0800
|
||||
Subject: [PATCH 4/5] Fix *sbp leak when running rpmbuild with --quiet
|
||||
|
||||
When running rpmbuild with --quiet, the "*sbp" may be alloced many
|
||||
times in buildSpec by calling doScript but only freed once. Fix it.
|
||||
---
|
||||
build/build.c | 3 +++
|
||||
1 file changed, 3 insertions(+)
|
||||
|
||||
diff --git a/build/build.c b/build/build.c
|
||||
index 9cd569b83..4437f6c9c 100644
|
||||
--- a/build/build.c
|
||||
+++ b/build/build.c
|
||||
@@ -216,6 +216,9 @@ rpmRC doScript(rpmSpec spec, rpmBuildFlags what, const char *name,
|
||||
buildCmd = rpmExpand(mCmd, " ", scriptName, NULL);
|
||||
(void) poptParseArgvString(buildCmd, &argc, &argv);
|
||||
|
||||
+ if (sb_stdoutp && *sb_stdoutp)
|
||||
+ *sb_stdoutp = freeStringBuf(*sb_stdoutp);
|
||||
+
|
||||
rpmlog(RPMLOG_NOTICE, _("Executing(%s): %s\n"), name, buildCmd);
|
||||
if (rpmfcExec((ARGV_const_t)argv, NULL, sb_stdoutp, 1,
|
||||
spec->buildSubdir)) {
|
||||
--
|
||||
2.27.0
|
||||
|
||||
13
rpm.spec
13
rpm.spec
@ -1,6 +1,6 @@
|
||||
Name: rpm
|
||||
Version: 4.17.0
|
||||
Release: 20
|
||||
Release: 21
|
||||
Summary: RPM Package Manager
|
||||
License: GPLv2+
|
||||
URL: http://www.rpm.org/
|
||||
@ -91,6 +91,14 @@ Patch6054: backport-Fix-h-blob-leak-when-installing-source-rpms.patch
|
||||
Patch6055: backport-Fix-Header-leak-when-running-rpm2cpio.patch
|
||||
Patch6056: backport-Use-unsigned-integers-more-consistently-in-the-handl.patch
|
||||
Patch6057: backport-Fix-file-leak-when-src-rpm-in-URL-format-is-used-for.patch
|
||||
Patch6058: backport-Fix-BANames-leak-in-handlePreambleTag.patch
|
||||
Patch6059: backport-Fix-prog-leak-in-parseScript.patch
|
||||
Patch6060: backport-Fix-elf-leak-in-getElfColor.patch
|
||||
Patch6061: backport-Fix-sbp-leak-when-running-rpmbuild-with-quiet.patch
|
||||
Patch6062: backport-Fix-memleak-when-running-generate_buildrequires.patch
|
||||
Patch6063: backport-Fix-memleak-when-fsmRename-failed-in-fsmCommit.patch
|
||||
Patch6064: backport-Fix-fileleak-and-memleak-in-rpmInstall.patch
|
||||
Patch6065: backport-Fix-fileleak-when-urlGetFile-fails-in-rpmInstall.patch
|
||||
|
||||
Patch9000: rpm-fix-rpm-is-blocked-when-open-fifo-file.patch
|
||||
|
||||
@ -373,6 +381,9 @@ make check || (cat tests/rpmtests.log; exit 0)
|
||||
%exclude %{_mandir}/man8/rpmspec.8.gz
|
||||
|
||||
%changelog
|
||||
* Mon Dec 26 2022 xujing<xujing125@huawei.com> - 4.17.0-21
|
||||
- backport patches from upstream to fix resource leak
|
||||
|
||||
* Mon Dec 19 2022 xujing<xujing125@huawei.com> - 4.17.0-20
|
||||
- Fix file leak when src rpm in URL format is used for installation
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user