Skip to content

Commit

Permalink
Merge pull request #291 from jrohel/fix/memLeaks_memAccess
Browse files Browse the repository at this point in the history
Fix: memory leaks, memory access, non used values
  • Loading branch information
mlschroe committed Dec 11, 2018
2 parents 591e59f + 2d7b115 commit 4830af9
Show file tree
Hide file tree
Showing 13 changed files with 34 additions and 10 deletions.
6 changes: 5 additions & 1 deletion examples/solv/fastestmirror.c
Expand Up @@ -68,7 +68,11 @@ findfastest(char **urls, int nurls)
socks[i] = socket(result->ai_family, result->ai_socktype, result->ai_protocol);
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 (errno != EINPROGRESS)
Expand Down
1 change: 0 additions & 1 deletion ext/pool_fileconflicts.c
Expand Up @@ -590,7 +590,6 @@ findfileconflicts_alias_cb(void *cbdatav, const char *fn, struct filelistinfo *i

if (!info->dirlen)
return;
dp = fn + info->dirlen;
if (info->diridx != cbdata->lastdiridx)
{
cbdata->lastdiridx = info->diridx;
Expand Down
2 changes: 1 addition & 1 deletion ext/repo_appdata.c
Expand Up @@ -103,7 +103,7 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
{
struct parsedata *pd = xmlp->userdata;
Pool *pool = pd->pool;
Solvable *s = pd->solvable;
Solvable *s;
const char *type;

/* ignore all language tags */
Expand Down
2 changes: 1 addition & 1 deletion ext/repo_comps.c
Expand Up @@ -107,7 +107,7 @@ startElement(struct solv_xmlparser *xmlp, int state, const char *name, const cha
{
struct parsedata *pd = xmlp->userdata;
Pool *pool = pd->pool;
Solvable *s = pd->solvable;
Solvable *s;

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

if (!headfromfp(&state, rpm, fp, lead, sigcnt, sigdsize, 0, chksumh, 0))
{
solv_chksum_free(chksumh, NULL);
fclose(fp);
return 0;
}
Expand Down
8 changes: 7 additions & 1 deletion ext/testcase.c
Expand Up @@ -576,6 +576,8 @@ testcase_str2dep_complex(Pool *pool, const char **sp, int relop)
Id flags, id, id2, namespaceid = 0;
struct oplist *op;

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

0 comments on commit 4830af9

Please sign in to comment.