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

View File

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

View File

@ -505,6 +505,7 @@ unpack_archive(struct xbps_handle *xhp,
0, pkgver, "%s: removed obsolete entry: %s", pkgver, file); 0, pkgver, "%s: removed obsolete entry: %s", pkgver, file);
xbps_object_release(obj); xbps_object_release(obj);
} }
/* XXX: cant free obsoletes here, need to copy values before */
xbps_object_release(pkg_filesd); xbps_object_release(pkg_filesd);
out: 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_iterator_release(iter);
xbps_object_release(pd);
return d; 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_release(array);
} }
xbps_object_iterator_release(iter); xbps_object_iterator_release(iter);
/* XXX: not possible to free shrequires without copying values */
xbps_object_release(shprovides); xbps_object_release(shprovides);
return unmatched; return unmatched;