summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPanu Matilainen <pmatilai@redhat.com>2012-08-01 19:17:09 +0300
committerPanu Matilainen <pmatilai@redhat.com>2012-10-03 10:12:44 +0300
commit0b07d23f25e4769b618a15bc4ba6e9df6f87bd42 (patch)
tree0f03b35abf40881cccbeec8f810b3e6134668b2b
parent610bacef64c51998e6d56f16b44ee2a6fedd60f5 (diff)
downloadrpm-0b07d23f25e4769b618a15bc4ba6e9df6f87bd42.tar.gz
rpm-0b07d23f25e4769b618a15bc4ba6e9df6f87bd42.tar.bz2
rpm-0b07d23f25e4769b618a15bc4ba6e9df6f87bd42.zip
Fix memleak in changelog parsing on error paths
- All the early returns would leak memory from the argvJoin(), assume failure and force all exits through a single path where we can clean up. (cherry picked from commit 395be24637b4ba555598df18f8feded097bbd03f)
-rw-r--r--build/parseChangelog.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/build/parseChangelog.c b/build/parseChangelog.c
index eed9842a2..ecf036258 100644
--- a/build/parseChangelog.c
+++ b/build/parseChangelog.c
@@ -113,6 +113,7 @@ exit:
*/
static rpmRC addChangelog(Header h, ARGV_const_t sb)
{
+ rpmRC rc = RPMRC_FAIL; /* assume failure */
char *s, *sp;
int i;
time_t time;
@@ -127,9 +128,8 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
while (*s != '\0') {
if (*s != '*') {
- rpmlog(RPMLOG_ERR,
- _("%%changelog entries must start with *\n"));
- return RPMRC_FAIL;
+ rpmlog(RPMLOG_ERR, _("%%changelog entries must start with *\n"));
+ goto exit;
}
/* find end of line */
@@ -137,7 +137,7 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
while(*s && *s != '\n') s++;
if (! *s) {
rpmlog(RPMLOG_ERR, _("incomplete %%changelog entry\n"));
- return RPMRC_FAIL;
+ goto exit;
}
*s = '\0';
text = s + 1;
@@ -152,12 +152,12 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
SKIPSPACE(date);
if (dateToTimet(date, &time)) {
rpmlog(RPMLOG_ERR, _("bad date in %%changelog: %s\n"), date);
- return RPMRC_FAIL;
+ goto exit;
}
if (lastTime && lastTime < time) {
rpmlog(RPMLOG_ERR,
_("%%changelog not in descending chronological order\n"));
- return RPMRC_FAIL;
+ goto exit;
}
lastTime = time;
@@ -165,7 +165,7 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
SKIPSPACE(s);
if (! *s) {
rpmlog(RPMLOG_ERR, _("missing name in %%changelog\n"));
- return RPMRC_FAIL;
+ goto exit;
}
/* name */
@@ -176,14 +176,14 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
}
if (s == name) {
rpmlog(RPMLOG_ERR, _("missing name in %%changelog\n"));
- return RPMRC_FAIL;
+ goto exit;
}
/* text */
SKIPSPACE(text);
if (! *text) {
rpmlog(RPMLOG_ERR, _("no description in %%changelog\n"));
- return RPMRC_FAIL;
+ goto exit;
}
/* find the next leading '*' (or eos) */
@@ -205,9 +205,12 @@ static rpmRC addChangelog(Header h, ARGV_const_t sb)
s = next;
}
+ rc = RPMRC_OK;
+
+exit:
free(sp);
- return RPMRC_OK;
+ return rc;
}
int parseChangelog(rpmSpec spec)