Skip to content
Permalink
Browse files

Merge pull request #291 from jrohel/fix/memLeaks_memAccess

Fix: memory leaks, memory access, non used values
  • Loading branch information...
mlschroe committed Dec 11, 2018
2 parents 591e59f + 2d7b115 commit 4830af9d979d3685de538b80fbeba51ad590525e
Showing with 34 additions and 10 deletions.
  1. +5 −1 examples/solv/fastestmirror.c
  2. +0 −1 ext/pool_fileconflicts.c
  3. +1 −1 ext/repo_appdata.c
  4. +1 −1 ext/repo_comps.c
  5. +1 −1 ext/repo_repomdxml.c
  6. +16 −0 ext/repo_rpmdb.c
  7. +7 −1 ext/testcase.c
  8. +0 −1 src/cleandeps.c
  9. +1 −1 src/dirpool.c
  10. +0 −1 src/order.c
  11. +1 −0 src/pool.c
  12. +0 −1 src/repopage.c
  13. +1 −0 tools/repo2solv.c
@@ -68,7 +68,11 @@ findfastest(char **urls, int nurls)
socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol); socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
if (socks[i] >= 0) if (socks[i] >= 0)
{ {
fcntl(socks[i], F_SETFL, O_NONBLOCK); if (fcntl(socks[i], F_SETFL, O_NONBLOCK) == -1)
{
close(socks[i]);
socks[i] = -1;
}
if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1) if (connect(socks[i], result->ai_addr, result->ai_addrlen) == -1)
{ {
if (errno != EINPROGRESS) if (errno != EINPROGRESS)
@@ -590,7 +590,6 @@ findfileconflicts_alias_cb(void *cbdatav, const char *fn, struct filelistinfo *i


if (!info->dirlen) if (!info->dirlen)
return; return;
dp = fn + info->dirlen;
if (info->diridx != cbdata->lastdiridx) if (info->diridx != cbdata->lastdiridx)
{ {
cbdata->lastdiridx = info->diridx; cbdata->lastdiridx = info->diridx;
@@ -103,7 +103,7 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
{ {
struct parsedata *pd = xmlp->userdata; struct parsedata *pd = xmlp->userdata;
Pool *pool = pd->pool; Pool *pool = pd->pool;
Solvable *s = pd->solvable; Solvable *s;
const char *type; const char *type;


/* ignore all language tags */ /* ignore all language tags */
@@ -107,7 +107,7 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
{ {
struct parsedata *pd = xmlp->userdata; struct parsedata *pd = xmlp->userdata;
Pool *pool = pd->pool; Pool *pool = pd->pool;
Solvable *s = pd->solvable; Solvable *s;


switch(state) switch(state)
{ {
@@ -181,7 +181,7 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
while (value) while (value)
{ {
char *p = strchr(value, ','); char *p = strchr(value, ',');
if (*p) if (p)
*p++ = 0; *p++ = 0;
if (*value) if (*value)
repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_UPDATES, value); repodata_add_poolstr_array(pd->data, SOLVID_META, REPOSITORY_UPDATES, value);
@@ -1896,6 +1896,8 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags)
if (fread(lead, 96 + 16, 1, fp) != 1 || getu32(lead) != 0xedabeedb) if (fread(lead, 96 + 16, 1, fp) != 1 || getu32(lead) != 0xedabeedb)
{ {
pool_error(pool, -1, "%s: not a rpm", rpm); pool_error(pool, -1, "%s: not a rpm", rpm);
solv_chksum_free(leadsigchksumh, NULL);
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
@@ -1908,12 +1910,16 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags)
if (lead[78] != 0 || lead[79] != 5) if (lead[78] != 0 || lead[79] != 5)
{ {
pool_error(pool, -1, "%s: not a rpm v5 header", rpm); pool_error(pool, -1, "%s: not a rpm v5 header", rpm);
solv_chksum_free(leadsigchksumh, NULL);
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
if (getu32(lead + 96) != 0x8eade801) if (getu32(lead + 96) != 0x8eade801)
{ {
pool_error(pool, -1, "%s: bad signature header", rpm); pool_error(pool, -1, "%s: bad signature header", rpm);
solv_chksum_free(leadsigchksumh, NULL);
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
@@ -1922,6 +1928,8 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags)
if (sigcnt >= MAX_SIG_CNT || sigdsize >= MAX_SIG_DSIZE) if (sigcnt >= MAX_SIG_CNT || sigdsize >= MAX_SIG_DSIZE)
{ {
pool_error(pool, -1, "%s: bad signature header", rpm); pool_error(pool, -1, "%s: bad signature header", rpm);
solv_chksum_free(leadsigchksumh, NULL);
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
@@ -1932,6 +1940,8 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags)
{ {
if (!headfromfp(&state, rpm, fp, lead + 96, sigcnt, sigdsize, sigpad, chksumh, leadsigchksumh)) if (!headfromfp(&state, rpm, fp, lead + 96, sigcnt, sigdsize, sigpad, chksumh, leadsigchksumh))
{ {
solv_chksum_free(leadsigchksumh, NULL);
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
@@ -1971,6 +1981,8 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags)
if (fread(lead, l, 1, fp) != 1) if (fread(lead, l, 1, fp) != 1)
{ {
pool_error(pool, -1, "%s: unexpected EOF", rpm); pool_error(pool, -1, "%s: unexpected EOF", rpm);
solv_chksum_free(leadsigchksumh, NULL);
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
@@ -1991,6 +2003,7 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags)
if (fread(lead, 16, 1, fp) != 1) if (fread(lead, 16, 1, fp) != 1)
{ {
pool_error(pool, -1, "%s: unexpected EOF", rpm); pool_error(pool, -1, "%s: unexpected EOF", rpm);
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
@@ -1999,6 +2012,7 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags)
if (getu32(lead) != 0x8eade801) if (getu32(lead) != 0x8eade801)
{ {
pool_error(pool, -1, "%s: bad header", rpm); pool_error(pool, -1, "%s: bad header", rpm);
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
@@ -2007,13 +2021,15 @@ repo_add_rpm(Repo *repo, const char *rpm, int flags)
if (sigcnt >= MAX_HDR_CNT || sigdsize >= MAX_HDR_DSIZE) if (sigcnt >= MAX_HDR_CNT || sigdsize >= MAX_HDR_DSIZE)
{ {
pool_error(pool, -1, "%s: bad header", rpm); pool_error(pool, -1, "%s: bad header", rpm);
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
headerend = headerstart + 16 + sigdsize + sigcnt * 16; headerend = headerstart + 16 + sigdsize + sigcnt * 16;


if (!headfromfp(&state, rpm, fp, lead, sigcnt, sigdsize, 0, chksumh, 0)) if (!headfromfp(&state, rpm, fp, lead, sigcnt, sigdsize, 0, chksumh, 0))
{ {
solv_chksum_free(chksumh, NULL);
fclose(fp); fclose(fp);
return 0; return 0;
} }
@@ -576,6 +576,8 @@ testcase_str2dep_complex(Pool *pool, const char **sp, int relop)
Id flags, id, id2, namespaceid = 0; Id flags, id, id2, namespaceid = 0;
struct oplist *op; struct oplist *op;


if (!s)
return 0;
while (*s == ' ' || *s == '\t') while (*s == ' ' || *s == '\t')
s++; s++;
if (!strncmp(s, "namespace:", 10)) if (!strncmp(s, "namespace:", 10))
@@ -2365,6 +2367,7 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
if (fclose(fp)) if (fclose(fp))
{ {
pool_error(solv->pool, 0, "testcase_write: write error"); pool_error(solv->pool, 0, "testcase_write: write error");
solv_free(result);
strqueue_free(&sq); strqueue_free(&sq);
return 0; return 0;
} }
@@ -2377,19 +2380,22 @@ testcase_write_mangled(Solver *solv, const char *dir, int resultflags, const cha
if (!(fp = fopen(out, "w"))) if (!(fp = fopen(out, "w")))
{ {
pool_error(solv->pool, 0, "testcase_write: could not open '%s' for writing", out); pool_error(solv->pool, 0, "testcase_write: could not open '%s' for writing", out);
solv_free(cmd);
strqueue_free(&sq); strqueue_free(&sq);
return 0; return 0;
} }
if (*cmd && fwrite(cmd, strlen(cmd), 1, fp) != 1) if (*cmd && fwrite(cmd, strlen(cmd), 1, fp) != 1)
{ {
pool_error(solv->pool, 0, "testcase_write: write error"); pool_error(solv->pool, 0, "testcase_write: write error");
solv_free(cmd);
strqueue_free(&sq); strqueue_free(&sq);
fclose(fp); fclose(fp);
return 0; return 0;
} }
if (fclose(fp)) if (fclose(fp))
{ {
pool_error(solv->pool, 0, "testcase_write: write error"); pool_error(solv->pool, 0, "testcase_write: write error");
solv_free(cmd);
strqueue_free(&sq); strqueue_free(&sq);
return 0; return 0;
} }
@@ -2789,7 +2795,7 @@ testcase_read(Pool *pool, FILE *fp, const char *testcase, Queue *job, char **res
{ {
int i = strlen(pieces[1]); int i = strlen(pieces[1]);
s = strchr(pieces[1], '('); s = strchr(pieces[1], '(');
if (!s && pieces[1][i - 1] != ')') if (!s || pieces[1][i - 1] != ')')
{ {
pool_error(pool, 0, "testcase_read: bad namespace '%s'", pieces[1]); pool_error(pool, 0, "testcase_read: bad namespace '%s'", pieces[1]);
} }
@@ -748,7 +748,6 @@ solver_createcleandepsmap(Solver *solv, Map *cleandepsmap, int unneeded)
continue; continue;
if (strncmp(pool_id2str(pool, s->name), "pattern:", 8) != 0) if (strncmp(pool_id2str(pool, s->name), "pattern:", 8) != 0)
continue; continue;
dp = s->repo->idarraydata + s->requires;
for (dp = s->repo->idarraydata + s->requires; *dp; dp++) for (dp = s->repo->idarraydata + s->requires; *dp; dp++)
FOR_PROVIDES(p, pp, *dp) FOR_PROVIDES(p, pp, *dp)
if (pool->solvables[p].repo == installed) if (pool->solvables[p].repo == installed)
@@ -85,7 +85,7 @@ dirpool_make_dirtraverse(Dirpool *dp)
return; return;
dp->dirs = solv_extend_resize(dp->dirs, dp->ndirs, sizeof(Id), DIR_BLOCK); dp->dirs = solv_extend_resize(dp->dirs, dp->ndirs, sizeof(Id), DIR_BLOCK);
dirtraverse = solv_calloc_block(dp->ndirs, sizeof(Id), DIR_BLOCK); dirtraverse = solv_calloc_block(dp->ndirs, sizeof(Id), DIR_BLOCK);
for (parent = 0, i = 0; i < dp->ndirs; i++) for (i = 0; i < dp->ndirs; i++)
{ {
if (dp->dirs[i] > 0) if (dp->dirs[i] > 0)
continue; continue;
@@ -1066,7 +1066,6 @@ transaction_order(Transaction *trans, int flags)
#if 0 #if 0
printf("do %s [%d]\n", pool_solvid2str(pool, te->p), temedianr[i]); printf("do %s [%d]\n", pool_solvid2str(pool, te->p), temedianr[i]);
#endif #endif
s = pool->solvables + te->p;
for (j = te->edges; od.invedgedata[j]; j++) for (j = te->edges; od.invedgedata[j]; j++)
{ {
struct s_TransactionElement *te2 = od.tes + od.invedgedata[j]; struct s_TransactionElement *te2 = od.tes + od.invedgedata[j];
@@ -1536,6 +1536,7 @@ pool_debug(Pool *pool, int type, const char *format, ...)
vprintf(format, args); vprintf(format, args);
else else
vfprintf(stderr, format, args); vfprintf(stderr, format, args);
va_end(args);
return; return;
} }
vsnprintf(buf, sizeof(buf), format, args); vsnprintf(buf, sizeof(buf), format, args);
@@ -399,7 +399,6 @@ compress_buf(const unsigned char *in, unsigned int in_len,
litlen -= 32; litlen -= 32;
} }
} }
litofs = 0;
} }
return oo; return oo;
} }
@@ -208,6 +208,7 @@ read_plaindir_repo(Repo *repo, const char *dir)
repodata_set_location(data, p, 0, 0, bp[0] == '.' && bp[1] == '/' ? bp + 2 : bp); repodata_set_location(data, p, 0, 0, bp[0] == '.' && bp[1] == '/' ? bp + 2 : bp);
solv_free(rpm); solv_free(rpm);
} }
solv_free(buf);
fclose(fp); fclose(fp);
while (waitpid(pid, &wstatus, 0) == -1) while (waitpid(pid, &wstatus, 0) == -1)
{ {

0 comments on commit 4830af9

Please sign in to comment.
You can’t perform that action at this time.