Skip to content

Commit

Permalink
Final round of low hanging leaks.
Browse files Browse the repository at this point in the history
Mostly detected by LeakSanitizer, but also extended to recurring patterns like not freeing buffer after getline.
  • Loading branch information
Keve authored and bapt committed Nov 30, 2024
1 parent 8186d23 commit 2cbdc3b
Show file tree
Hide file tree
Showing 9 changed files with 49 additions and 7 deletions.
10 changes: 9 additions & 1 deletion Leak.suppress.in
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,12 @@ leak:dyld4::Loader::*
# #3 0x7f2a7f11b004 in BUF_MEM_new_ex (/lib/x86_64-linux-gnu/libcrypto.so.3+0x11b004) (BuildId: c503df82cf13681b2f81e1097e857e3fc50679b1)
# #4 0x7f2a7f0f79dd (/lib/x86_64-linux-gnu/libcrypto.so.3+0xf79dd) (BuildId: c503df82cf13681b2f81e1097e857e3fc50679b1)
# #5 0x7f2a7f0ed883 in BIO_new_ex (/lib/x86_64-linux-gnu/libcrypto.so.3+0xed883) (BuildId: c503df82cf13681b2f81e1097e857e3fc50679b1)
leak:BIO_new_ex
leak:BIO_new_ex

# UCL should be investigated first within UCL, there is plenty to look at
leak:ucl_parser_add_fd

## FIXME: Temporarily suppress inside pkg source

# this could be a dangling pointer false positive report, the whole function should be re-structured
leak:pkgdb_open_all2
1 change: 1 addition & 0 deletions libpkg/pkg.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ pkg_free(struct pkg *pkg)
free(pkg->desc);
free(pkg->sum);
free(pkg->repopath);
free(pkg->reponame);
free(pkg->repourl);
free(pkg->reason);
free(pkg->dep_formula);
Expand Down
4 changes: 3 additions & 1 deletion libpkg/pkg_delete.c
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,10 @@ pkg_effective_rmdir(struct pkgdb *db, struct pkg *pkg)
char prefix_r[MAXPATHLEN];

snprintf(prefix_r, sizeof(prefix_r), "%s", pkg->prefix[0] ? pkg->prefix + 1 : "");
tll_foreach(pkg->dir_to_del, d)
tll_foreach(pkg->dir_to_del, d) {
rmdir_p(db, pkg, d->item, prefix_r);
tll_remove_and_free(pkg->dir_to_del, d, free);
}
}

void
Expand Down
1 change: 1 addition & 0 deletions libpkg/pkg_jobs_universe.c
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,7 @@ pkg_jobs_universe_free(struct pkg_jobs_universe *universe)
while (pkghash_next(&it))
pkg_jobs_universe_provide_free(it.value);
pkghash_destroy(universe->provides);
free(universe);
}

struct pkg_jobs_universe *
Expand Down
6 changes: 4 additions & 2 deletions libpkg/pkg_manifest.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@ pkg_set_files_from_object(struct pkg *pkg, const ucl_object_t *obj)
const char *sum = NULL;
const char *uname = NULL;
const char *gname = NULL;
void *set = NULL;
mode_t perm = 0;
xstring *fname = NULL;
const char *key, *okey;
Expand All @@ -631,11 +630,13 @@ pkg_set_files_from_object(struct pkg *pkg, const ucl_object_t *obj)
sum = ucl_object_tostring(cur);
else if (STRIEQ(key, "perm") &&
(cur->type == UCL_STRING || cur->type == UCL_INT)) {
void *set = 0;
if ((set = setmode(ucl_object_tostring_forced(cur))) == NULL)
pkg_emit_error("Not a valid mode: %s",
ucl_object_tostring(cur));
else
perm = getmode(set, 0);
free(set);
} else {
dbg(1, "Skipping unknown key for file(%s): %s",
fname->buf, key);
Expand All @@ -656,7 +657,6 @@ pkg_set_dirs_from_object(struct pkg *pkg, const ucl_object_t *obj)
ucl_object_iter_t it = NULL;
const char *uname = NULL;
const char *gname = NULL;
void *set;
mode_t perm = 0;
xstring *dirname = NULL;
const char *key, *okey;
Expand All @@ -675,11 +675,13 @@ pkg_set_dirs_from_object(struct pkg *pkg, const ucl_object_t *obj)
gname = ucl_object_tostring(cur);
else if (STRIEQ(key, "perm") &&
(cur->type == UCL_STRING || cur->type == UCL_INT)) {
void *set = 0;
if ((set = setmode(ucl_object_tostring_forced(cur))) == NULL)
pkg_emit_error("Not a valid mode: %s",
ucl_object_tostring(cur));
else
perm = getmode(set, 0);
free(set);
} else if (STRIEQ(key, "try") && cur->type == UCL_BOOLEAN) {
/* ignore on purpose : compatibility*/
} else {
Expand Down
3 changes: 3 additions & 0 deletions libpkg/pkg_repo_create.c
Original file line number Diff line number Diff line change
Expand Up @@ -1020,6 +1020,7 @@ pkg_repo_sign(const char *path, char **argv, int argc, char **sig, size_t *sigle
fwrite(line, linelen, 1, buf->fp);
}
}
free(line);

*sigtype = xstring_get(typestr);
*cert = xstring_get_binary(certstr, certlen);
Expand Down Expand Up @@ -1131,6 +1132,8 @@ pack_command_sign(struct packing *pack, const char *path, char **argv, int argc,

iov[offset].iov_base = buf;
iov[offset++].iov_len = size;
} else {
free(sigtype);
}

iov[offset].iov_base = sig;
Expand Down
28 changes: 25 additions & 3 deletions src/updating.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,25 @@ struct regex_cache {
regex_t reg;
};


static void
installed_ports_free(struct installed_ports *p)
{
if (!p)
return;
free(p->origin);
free(p);
}

static void
regex_cache_free(struct regex_cache *p)
{
if (!p)
return;
free(p->pattern);
free(p);
}

void
usage_updating(void)
{
Expand Down Expand Up @@ -199,14 +218,13 @@ matcher(const char *affects, const char *origin, bool ignorecase)
goto out;
}
if ((ent->pattern = strdup(words[i])) == NULL) {
free(ent);
regex_cache_free(ent);
ret = 0;
goto out;
}
re = convert_re(words[i]);
if (re == NULL) {
free(ent->pattern);
free(ent);
regex_cache_free(ent);
ret = 0;
goto out;
}
Expand All @@ -221,6 +239,8 @@ matcher(const char *affects, const char *origin, bool ignorecase)
}

out:
tll_foreach(cache, it)
tll_remove_and_free(cache, it, regex_cache_free);
free(words);
free(buf);
return (ret);
Expand Down Expand Up @@ -381,6 +401,8 @@ exec_updating(int argc, char **argv)
fclose(fd);

cleanup:
tll_foreach(origins, it)
tll_remove_and_free(origins, it, installed_ports_free);
pkgdb_it_free(it);
pkgdb_release_lock(db, PKGDB_LOCK_READONLY);
pkgdb_close(db);
Expand Down
2 changes: 2 additions & 0 deletions src/upgrade.c
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,8 @@ add_vulnerable_upgrades(struct pkg_jobs *jobs, struct pkgdb *db)
}
}

free(line);

fclose(in);

while (waitpid(cld, &retcode, 0) == -1) {
Expand Down
1 change: 1 addition & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ vquery_yesno(bool deft, const char *msg, va_list ap)
}
}

free(line);
free(out);

return (r);
Expand Down

0 comments on commit 2cbdc3b

Please sign in to comment.