Merge pull request #206 from Duncaen/memleak

fix some some memory leaks
This commit is contained in:
Juan RP 2017-02-19 02:46:50 +01:00 committed by GitHub
commit 1670ff000d
4 changed files with 20 additions and 6 deletions

View File

@ -209,14 +209,14 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
fprintf(stderr, "xbps-rindex: cannot lock repository "
"%s: %s\n", repodir, strerror(errno));
rv = -1;
goto out;
goto earlyout;
}
repo = xbps_repo_public_open(xhp, repodir);
if (repo == NULL && errno != ENOENT) {
fprintf(stderr, "xbps-rindex: cannot open/lock repository "
"%s: %s\n", repodir, strerror(errno));
rv = -1;
goto out;
goto earlyout;
}
if (repo) {
idx = xbps_dictionary_copy_mutable(repo->idx);
@ -230,7 +230,7 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
fprintf(stderr, "xbps-rindex: cannot open/lock stage repository "
"%s: %s\n", repodir, strerror(errno));
rv = -1;
goto out;
goto earlyout;
}
if (stage) {
idxstage = xbps_dictionary_copy_mutable(stage->idx);
@ -277,6 +277,7 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
if (curpkgd == NULL) {
if (errno && errno != ENOENT) {
rv = errno;
xbps_object_release(binpkgd);
free(pkgver);
free(pkgname);
goto out;
@ -322,12 +323,14 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
* - filename-sha256
*/
if ((sha256 = xbps_file_hash(pkg)) == NULL) {
xbps_object_release(binpkgd);
free(pkgver);
free(pkgname);
rv = EINVAL;
goto out;
}
if (!xbps_dictionary_set_cstring(binpkgd, "filename-sha256", sha256)) {
xbps_object_release(binpkgd);
free(sha256);
free(pkgver);
free(pkgname);
@ -336,18 +339,21 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
}
free(sha256);
if (stat(pkg, &st) == -1) {
xbps_object_release(binpkgd);
free(pkgver);
free(pkgname);
rv = EINVAL;
goto out;
}
if (!xbps_dictionary_set_uint64(binpkgd, "filename-size", (uint64_t)st.st_size)) {
xbps_object_release(binpkgd);
free(pkgver);
free(pkgname);
rv = EINVAL;
goto out;
}
if (set_build_date(binpkgd, st.st_mtime) < 0) {
xbps_object_release(binpkgd);
free(pkgver);
free(pkgname);
rv = EINVAL;
@ -362,6 +368,7 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
* Add new pkg dictionary into the stage index
*/
if (!xbps_dictionary_set(idxstage, pkgname, binpkgd)) {
xbps_object_release(binpkgd);
free(pkgname);
free(pkgver);
rv = EINVAL;
@ -382,6 +389,12 @@ index_add(struct xbps_handle *xhp, int args, int argmax, char **argv, bool force
printf("index: %u packages registered.\n", xbps_dictionary_count(idx));
out:
xbps_object_release(idx);
xbps_object_release(idxstage);
if (idxmeta)
xbps_object_release(idxmeta);
earlyout:
if (repo)
xbps_repo_close(repo);
if (stage)

View File

@ -111,11 +111,11 @@ xbps_configure_pkg(struct xbps_handle *xhp,
free(pkgname);
return ENOENT;
}
free(pkgname);
rv = xbps_pkg_state_dictionary(pkgd, &state);
xbps_dbg_printf(xhp, "%s: state %d rv %d\n", pkgver, state, rv);
if (rv != 0) {
free(pkgname);
xbps_dbg_printf(xhp, "%s: [configure] failed to get "
"pkg state: %s\n", pkgver, strerror(rv));
return EINVAL;
@ -124,11 +124,9 @@ xbps_configure_pkg(struct xbps_handle *xhp,
if (check_state) {
if (state == XBPS_PKG_STATE_INSTALLED) {
if ((xhp->flags & XBPS_FLAG_FORCE_CONFIGURE) == 0) {
free(pkgname);
return 0;
}
} else if (state != XBPS_PKG_STATE_UNPACKED) {
free(pkgname);
return EINVAL;
}
}

View File

@ -505,6 +505,7 @@ unpack_archive(struct xbps_handle *xhp,
0, pkgver, "%s: removed obsolete entry: %s", pkgver, file);
xbps_object_release(obj);
}
/* XXX: cant free obsoletes here, need to copy values before */
xbps_object_release(pkg_filesd);
out:
/*

View File

@ -132,6 +132,7 @@ collect_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, bool req)
}
}
xbps_object_iterator_release(iter);
xbps_object_release(pd);
return d;
}
@ -176,6 +177,7 @@ xbps_transaction_shlibs(struct xbps_handle *xhp, xbps_array_t pkgs, xbps_array_t
xbps_object_release(array);
}
xbps_object_iterator_release(iter);
/* XXX: not possible to free shrequires without copying values */
xbps_object_release(shprovides);
return unmatched;