libxbps: simplify pkgdb_get_pkgd and find_pkg_dict_installed internals.
There's no need to prop_dictionary_copy the returned dictionary to later have to free it again, just return directly the dictionary and avoid the free(3)s.
This commit is contained in:
parent
068cab8d20
commit
974b2fe8ad
@ -185,8 +185,6 @@ out:
|
||||
prop_object_release(filesd);
|
||||
if (prop_object_type(propsd) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(propsd);
|
||||
if (prop_object_type(opkgd) == PROP_TYPE_DICTIONARY)
|
||||
prop_object_release(opkgd);
|
||||
if (broken)
|
||||
return 1;
|
||||
|
||||
|
@ -162,10 +162,8 @@ remove_stale_entries_in_reqby(struct xbps_handle *xhp,
|
||||
|
||||
for (i = 0; i < prop_array_count(reqby); i++) {
|
||||
prop_array_get_cstring_nocopy(reqby, i, &str);
|
||||
if ((pkgd = xbps_pkgdb_get_pkgd_by_pkgver(xhp, str)) != NULL) {
|
||||
prop_object_release(pkgd);
|
||||
if ((pkgd = xbps_pkgdb_get_pkgd_by_pkgver(xhp, str)) != NULL)
|
||||
continue;
|
||||
}
|
||||
printf("%s: found stale entry in requiredby `%s' (fixed)\n",
|
||||
crd->pkgver, str);
|
||||
if (xbps_remove_string_from_array(xhp, crd->pkgd_reqby, str))
|
||||
|
@ -76,7 +76,6 @@ show_pkg_reverse_deps(struct xbps_handle *xhp, const char *pkgname)
|
||||
}
|
||||
rv = xbps_callback_array_iter_in_dict(xhp, pkgd, "requiredby",
|
||||
list_strings_sep_in_array, NULL);
|
||||
prop_object_release(pkgd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
@ -89,7 +89,6 @@ state_cb(struct xbps_handle *xhp,
|
||||
pkgd = xbps_find_pkg_dict_installed(xhp,
|
||||
xscd->pkgname, false);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "version", &version);
|
||||
prop_object_release(pkgd);
|
||||
printf("Updating `%s' (`%s' to `%s') ...\n", xscd->pkgname,
|
||||
version, xscd->version);
|
||||
break;
|
||||
|
@ -337,7 +337,6 @@ remove_pkg(struct xbps_handle *xhp, const char *pkgname, bool recursive)
|
||||
pkgd = xbps_find_pkg_dict_installed(xhp, pkgname, false);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd, "pkgver", &pkgver);
|
||||
reqby = prop_dictionary_get(pkgd, "requiredby");
|
||||
prop_object_release(pkgd);
|
||||
printf("WARNING: %s IS REQUIRED BY %u PACKAGE%s:\n\n",
|
||||
pkgver, prop_array_count(reqby),
|
||||
prop_array_count(reqby) > 1 ? "S" : "");
|
||||
|
@ -197,7 +197,6 @@ main(int argc, char **argv)
|
||||
"pkgname", &pkgn);
|
||||
prop_dictionary_get_cstring_nocopy(pkgd,
|
||||
"version", &version);
|
||||
prop_object_release(pkgd);
|
||||
fprintf(stderr, "%s%s=> ERROR: `%s-%s' is already "
|
||||
"registered!%s\n", MSG_ERROR,
|
||||
in_chroot ? "[chroot] " : "",
|
||||
@ -251,7 +250,6 @@ main(int argc, char **argv)
|
||||
}
|
||||
prop_dictionary_get_cstring_nocopy(dict, "version", &version);
|
||||
printf("%s\n", version);
|
||||
prop_object_release(dict);
|
||||
} else if (strcasecmp(argv[0], "sanitize-plist") == 0) {
|
||||
/* Sanitize a plist file (properly indent the file) */
|
||||
if (argc != 2)
|
||||
|
@ -56,7 +56,7 @@
|
||||
*/
|
||||
#define XBPS_PKGINDEX_VERSION "1.5"
|
||||
|
||||
#define XBPS_API_VERSION "20120615"
|
||||
#define XBPS_API_VERSION "20120616"
|
||||
#define XBPS_VERSION "0.16"
|
||||
|
||||
/**
|
||||
@ -714,9 +714,7 @@ int xbps_pkgdb_foreach_reverse_cb(
|
||||
* @param[in] bypattern If false \a pkg must be a pkgname, otherwise a
|
||||
* package pattern, i.e `foo>=0' or `foo<1'.
|
||||
*
|
||||
* @return The matching proplib package dictionary from pkgdb copied
|
||||
* with \a prop_dictionary_copy() so it must be released when not required
|
||||
* anymore with prop_object_release(). NULL otherwise.
|
||||
* @return The matching proplib package dictionary, NULL otherwise.
|
||||
*/
|
||||
prop_dictionary_t xbps_pkgdb_get_pkgd(struct xbps_handle *xhp,
|
||||
const char *pkg,
|
||||
@ -729,9 +727,7 @@ prop_dictionary_t xbps_pkgdb_get_pkgd(struct xbps_handle *xhp,
|
||||
* @param[in] xhp The pointer to the xbps_handle struct.
|
||||
* @param[in] pkgver Package name-version to match, i.e 'foo-1.0'.
|
||||
*
|
||||
* @return The matching proplib package dictionary from pkgdb copied
|
||||
* with \a prop_dictionary_copy() so it must be released when not required
|
||||
* anymore with prop_object_release(). NULL otherwise.
|
||||
* @return The matching proplib package dictionary, NULL otherwise.
|
||||
*/
|
||||
prop_dictionary_t xbps_pkgdb_get_pkgd_by_pkgver(struct xbps_handle *xhp,
|
||||
const char *pkgver);
|
||||
@ -1002,8 +998,6 @@ prop_dictionary_t xbps_find_virtualpkg_in_dict_by_pattern(struct xbps_handle *xh
|
||||
*
|
||||
* @return The package's dictionary on success, NULL otherwise and
|
||||
* errno is set appropiately.
|
||||
* @note When returned dictionary is no longer needed, it must be released
|
||||
* with prop_object_release(3).
|
||||
*/
|
||||
prop_dictionary_t xbps_find_pkg_dict_installed(struct xbps_handle *xhp,
|
||||
const char *str,
|
||||
@ -1021,8 +1015,6 @@ prop_dictionary_t xbps_find_pkg_dict_installed(struct xbps_handle *xhp,
|
||||
*
|
||||
* @return The virtual package's dictionary on success, NULL otherwise and
|
||||
* errno is set appropiately.
|
||||
* @note When returned dictionary is no longer needed, it must be released
|
||||
* with prop_object_release(3).
|
||||
*/
|
||||
prop_dictionary_t xbps_find_virtualpkg_dict_installed(struct xbps_handle *xhp,
|
||||
const char *str,
|
||||
|
@ -103,16 +103,11 @@ xbps_configure_pkg(struct xbps_handle *xhp,
|
||||
}
|
||||
|
||||
if (state == XBPS_PKG_STATE_INSTALLED) {
|
||||
if ((xhp->flags & XBPS_FLAG_FORCE_CONFIGURE) == 0) {
|
||||
prop_object_release(pkgd);
|
||||
if ((xhp->flags & XBPS_FLAG_FORCE_CONFIGURE) == 0)
|
||||
return 0;
|
||||
}
|
||||
} else if (state != XBPS_PKG_STATE_UNPACKED) {
|
||||
prop_object_release(pkgd);
|
||||
} else if (state != XBPS_PKG_STATE_UNPACKED)
|
||||
return EINVAL;
|
||||
}
|
||||
}
|
||||
prop_object_release(pkgd);
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_CONFIGURE, 0, pkgname, version, NULL);
|
||||
|
||||
buf = xbps_xasprintf("%s/metadata/%s/INSTALL",
|
||||
|
@ -59,7 +59,6 @@ xbps_pkg_find_conflicts(struct xbps_handle *xhp, prop_dictionary_t pkg_repod)
|
||||
"installed pkg %s", repopkgver, pkgver);
|
||||
assert(buf != NULL);
|
||||
prop_array_add_cstring(trans_cflicts, buf);
|
||||
prop_object_release(pkgd);
|
||||
free(buf);
|
||||
continue;
|
||||
}
|
||||
|
@ -137,9 +137,6 @@ xbps_register_pkg(struct xbps_handle *xhp, prop_dictionary_t pkgrd, bool flush)
|
||||
goto out;
|
||||
}
|
||||
out:
|
||||
if (pkgd != NULL)
|
||||
prop_object_release(pkgd);
|
||||
|
||||
if (rv != 0) {
|
||||
xbps_set_cb_state(xhp, XBPS_STATE_REGISTER_FAIL,
|
||||
rv, pkgname, version,
|
||||
|
@ -107,7 +107,6 @@ xbps_pkg_state_installed(struct xbps_handle *xhp,
|
||||
return ENOENT;
|
||||
|
||||
*state = get_state(pkgd);
|
||||
prop_object_release(pkgd);
|
||||
if (*state == 0)
|
||||
return EINVAL;
|
||||
|
||||
@ -203,11 +202,8 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
|
||||
if (pkgd == NULL) {
|
||||
newpkg = true;
|
||||
pkgd = prop_dictionary_create();
|
||||
rv = set_pkg_objs(pkgd, pkgname, version);
|
||||
if (rv != 0) {
|
||||
prop_object_release(pkgd);
|
||||
if ((rv = set_pkg_objs(pkgd, pkgname, version)) != 0)
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
if ((rv = set_new_state(pkgd, state)) != 0) {
|
||||
if (newpkg)
|
||||
@ -223,8 +219,6 @@ xbps_set_pkg_state_installed(struct xbps_handle *xhp,
|
||||
if ((rv = xbps_array_replace_dict_by_name(xhp->pkgdb,
|
||||
pkgd, pkgname)) != 0)
|
||||
return rv;
|
||||
|
||||
prop_object_release(pkgd);
|
||||
}
|
||||
}
|
||||
|
||||
|
13
lib/pkgdb.c
13
lib/pkgdb.c
@ -169,25 +169,16 @@ xbps_pkgdb_get_pkgd(struct xbps_handle *xhp, const char *pkg, bool bypattern)
|
||||
else
|
||||
pkgd = xbps_find_pkg_in_array_by_name(xhp, xhp->pkgdb, pkg, NULL);
|
||||
|
||||
if (pkgd != NULL)
|
||||
return prop_dictionary_copy(pkgd);
|
||||
|
||||
return NULL;
|
||||
return pkgd;
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
xbps_pkgdb_get_pkgd_by_pkgver(struct xbps_handle *xhp, const char *pkgver)
|
||||
{
|
||||
prop_dictionary_t pkgd = NULL;
|
||||
|
||||
if (xbps_pkgdb_init(xhp) != 0)
|
||||
return NULL;
|
||||
|
||||
pkgd = xbps_find_pkg_in_array_by_pkgver(xhp, xhp->pkgdb, pkgver, NULL);
|
||||
if (pkgd != NULL)
|
||||
return prop_dictionary_copy(pkgd);
|
||||
|
||||
return NULL;
|
||||
return xbps_find_pkg_in_array_by_pkgver(xhp, xhp->pkgdb, pkgver, NULL);
|
||||
}
|
||||
|
||||
bool
|
||||
|
@ -294,7 +294,6 @@ xbps_dictionary_from_metadata_plist(struct xbps_handle *xhp,
|
||||
"pkgname", &savedpkgname);
|
||||
plistf = xbps_xasprintf("%s/metadata/%s/%s",
|
||||
xhp->metadir, savedpkgname, plist);
|
||||
prop_object_release(pkgd);
|
||||
if (plistf == NULL)
|
||||
return NULL;
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ find_pkgd_installed(struct xbps_handle *xhp,
|
||||
bool bypattern,
|
||||
bool virtual)
|
||||
{
|
||||
prop_dictionary_t pkgd, rpkgd = NULL;
|
||||
prop_dictionary_t pkgd = NULL;
|
||||
pkg_state_t state = 0;
|
||||
int rv;
|
||||
|
||||
@ -376,20 +376,20 @@ find_pkgd_installed(struct xbps_handle *xhp,
|
||||
return NULL;
|
||||
|
||||
if (xbps_pkg_state_dictionary(pkgd, &state) != 0)
|
||||
return rpkgd;
|
||||
return NULL;
|
||||
|
||||
switch (state) {
|
||||
case XBPS_PKG_STATE_INSTALLED:
|
||||
case XBPS_PKG_STATE_UNPACKED:
|
||||
rpkgd = prop_dictionary_copy(pkgd);
|
||||
break;
|
||||
return pkgd;
|
||||
/* NOTREACHED */
|
||||
default:
|
||||
/* not fully installed */
|
||||
errno = ENOENT;
|
||||
break;
|
||||
}
|
||||
|
||||
return rpkgd;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
|
@ -245,11 +245,8 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
"pkgver", &pkgver_q);
|
||||
|
||||
/* Check its state */
|
||||
rv = xbps_pkg_state_dictionary(tmpd, &state);
|
||||
if (rv != 0) {
|
||||
prop_object_release(tmpd);
|
||||
if ((rv = xbps_pkg_state_dictionary(tmpd, &state)) != 0)
|
||||
break;
|
||||
}
|
||||
if (xbps_match_virtual_pkg_in_dict(tmpd,reqpkg,true)) {
|
||||
/*
|
||||
* Check if required dependency is a virtual
|
||||
@ -259,7 +256,6 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
xbps_dbg_printf_append(xhp,
|
||||
"[virtual] satisfied by "
|
||||
"`%s'.\n", pkgver_q);
|
||||
prop_object_release(tmpd);
|
||||
continue;
|
||||
}
|
||||
rv = xbps_pkgpattern_match(pkgver_q, reqpkg);
|
||||
@ -294,12 +290,10 @@ find_repo_deps(struct xbps_handle *xhp,
|
||||
xbps_dbg_printf_append(xhp,
|
||||
"installed "
|
||||
"`%s'.\n", pkgver_q);
|
||||
prop_object_release(tmpd);
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
/* error matching pkgpattern */
|
||||
prop_object_release(tmpd);
|
||||
xbps_dbg_printf(xhp, "failed to match "
|
||||
"pattern %s with %s\n", reqpkg, pkgver_q);
|
||||
break;
|
||||
|
@ -135,9 +135,11 @@ xbps_rpool_release(struct xbps_handle *xhp)
|
||||
for (i = 0; i < prop_array_count(xhp->repo_pool); i++) {
|
||||
d = prop_array_get(xhp->repo_pool, i);
|
||||
idx = prop_dictionary_get(d, "index");
|
||||
prop_dictionary_get_cstring_nocopy(d, "uri", &uri);
|
||||
xbps_dbg_printf(xhp, "[rpool] unregistered repository '%s'\n",
|
||||
uri);
|
||||
if (xhp->flags & XBPS_FLAG_DEBUG) {
|
||||
prop_dictionary_get_cstring_nocopy(d, "uri", &uri);
|
||||
xbps_dbg_printf(xhp, "[rpool] unregistered "
|
||||
"repository '%s'\n", uri);
|
||||
}
|
||||
prop_object_release(idx);
|
||||
prop_object_release(d);
|
||||
}
|
||||
|
@ -121,7 +121,6 @@ transaction_find_pkg(struct xbps_handle *xhp,
|
||||
*/
|
||||
prop_dictionary_get_cstring_nocopy(pkg_pkgdb,
|
||||
"version", &instver);
|
||||
prop_object_release(pkg_pkgdb);
|
||||
if (xbps_cmpver(repover, instver) <= 0) {
|
||||
xbps_dbg_printf(xhp, "[rpool] Skipping `%s-%s' "
|
||||
"(installed: %s-%s) from repository `%s'\n",
|
||||
@ -279,11 +278,8 @@ xbps_transaction_install_pkg(struct xbps_handle *xhp,
|
||||
pkgd = xbps_pkgdb_get_pkgd(xhp, pkg, bypattern);
|
||||
|
||||
if (pkgd) {
|
||||
if (xbps_pkg_state_dictionary(pkgd, &state) != 0) {
|
||||
prop_object_release(pkgd);
|
||||
if (xbps_pkg_state_dictionary(pkgd, &state) != 0)
|
||||
return EINVAL;
|
||||
}
|
||||
prop_object_release(pkgd);
|
||||
if ((state == XBPS_PKG_STATE_INSTALLED) && !reinstall) {
|
||||
/* error out if pkg installed and no reinstall */
|
||||
return EEXIST;
|
||||
@ -315,7 +311,7 @@ xbps_transaction_remove_pkg(struct xbps_handle *xhp,
|
||||
* Prepare transaction dictionary and missing deps array.
|
||||
*/
|
||||
if ((rv = xbps_transaction_init(xhp)) != 0)
|
||||
goto out;
|
||||
return rv;
|
||||
|
||||
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
|
||||
if (!recursive)
|
||||
@ -324,19 +320,14 @@ xbps_transaction_remove_pkg(struct xbps_handle *xhp,
|
||||
* If recursive is set, find out which packages would be orphans
|
||||
* if the supplied package were already removed.
|
||||
*/
|
||||
orphans_pkg = prop_array_create();
|
||||
if (orphans_pkg == NULL) {
|
||||
rv = ENOMEM;
|
||||
goto out;
|
||||
}
|
||||
if ((orphans_pkg = prop_array_create()) == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
prop_array_set_cstring_nocopy(orphans_pkg, 0, pkgname);
|
||||
orphans = xbps_find_pkg_orphans(xhp, orphans_pkg);
|
||||
prop_object_release(orphans_pkg);
|
||||
if (prop_object_type(orphans) != PROP_TYPE_ARRAY) {
|
||||
rv = EINVAL;
|
||||
goto out;
|
||||
}
|
||||
if (prop_object_type(orphans) != PROP_TYPE_ARRAY)
|
||||
return EINVAL;
|
||||
|
||||
count = prop_array_count(orphans);
|
||||
while (count--) {
|
||||
@ -364,9 +355,6 @@ rmpkg:
|
||||
(prop_array_count(reqby) > 0))
|
||||
rv = EEXIST;
|
||||
|
||||
out:
|
||||
prop_object_release(pkgd);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
@ -95,7 +95,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
xbps_dbg_printf(xhp,
|
||||
"replaced and new package "
|
||||
"are equal (%s)\n", pkgname);
|
||||
prop_object_release(instd);
|
||||
continue;
|
||||
}
|
||||
instd_reqby = prop_dictionary_get(instd, "requiredby");
|
||||
@ -181,7 +180,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
if (xbps_mkpath(dname, 0755) == -1) {
|
||||
if (errno != EEXIST) {
|
||||
free(buf);
|
||||
prop_object_release(instd);
|
||||
prop_object_iterator_release(iter);
|
||||
return errno;
|
||||
}
|
||||
@ -190,7 +188,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
free(buf);
|
||||
free(dirc);
|
||||
prop_object_release(filesd);
|
||||
prop_object_release(instd);
|
||||
prop_object_iterator_release(iter);
|
||||
return errno;
|
||||
}
|
||||
@ -205,7 +202,6 @@ xbps_transaction_package_replace(struct xbps_handle *xhp)
|
||||
prop_dictionary_set_cstring_nocopy(instd,
|
||||
"transaction", "remove");
|
||||
if (!xbps_add_obj_to_array(transd_unsorted, instd)) {
|
||||
prop_object_release(instd);
|
||||
prop_object_iterator_release(iter);
|
||||
return EINVAL;
|
||||
}
|
||||
|
10
lib/util.c
10
lib/util.c
@ -83,15 +83,10 @@ xbps_check_is_installed_pkg_by_pattern(struct xbps_handle *xhp,
|
||||
* Check that package state is fully installed, not
|
||||
* unpacked or something else.
|
||||
*/
|
||||
if (xbps_pkg_state_dictionary(dict, &state) != 0) {
|
||||
prop_object_release(dict);
|
||||
if (xbps_pkg_state_dictionary(dict, &state) != 0)
|
||||
return -1; /* error */
|
||||
}
|
||||
if (state != XBPS_PKG_STATE_INSTALLED) {
|
||||
prop_object_release(dict);
|
||||
if (state != XBPS_PKG_STATE_INSTALLED)
|
||||
return 0; /* not fully installed */
|
||||
}
|
||||
prop_object_release(dict);
|
||||
|
||||
return 1;
|
||||
}
|
||||
@ -108,7 +103,6 @@ xbps_check_is_installed_pkg_by_name(struct xbps_handle *xhp,
|
||||
((pkgd = xbps_find_virtualpkg_dict_installed(xhp, pkgname, false)) == NULL))
|
||||
return false;
|
||||
|
||||
prop_object_release(pkgd);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user