bin/xbps-rindex: fix memleaks in index_add
This commit is contained in:
parent
7d06fb0e71
commit
81673d69c7
@ -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)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user