libxbps: use memcpy in critical paths for performance, fixed some memleaks.
This commit is contained in:
parent
3e93d235ff
commit
c24ce8e4da
@ -56,7 +56,7 @@
|
||||
*/
|
||||
#define XBPS_PKGINDEX_VERSION "1.5"
|
||||
|
||||
#define XBPS_API_VERSION "20120616"
|
||||
#define XBPS_API_VERSION "20120618"
|
||||
#define XBPS_VERSION "0.16"
|
||||
|
||||
/**
|
||||
|
@ -222,9 +222,7 @@ xbps_end(struct xbps_handle *xhp)
|
||||
xbps_rpool_release(xhp);
|
||||
xbps_fetch_unset_cache_connection();
|
||||
|
||||
if (xhp->cfg != NULL)
|
||||
cfg_free(xhp->cfg);
|
||||
|
||||
free(xhp->cachedir_priv);
|
||||
free(xhp->metadir_priv);
|
||||
free(xhp->un_machine);
|
||||
|
@ -81,8 +81,7 @@ xbps_rpool_init(struct xbps_handle *xhp)
|
||||
/*
|
||||
* Register repository into the array.
|
||||
*/
|
||||
d = prop_dictionary_create();
|
||||
if (d == NULL) {
|
||||
if ((d = prop_dictionary_create()) == NULL) {
|
||||
rv = ENOMEM;
|
||||
prop_object_release(array);
|
||||
goto out;
|
||||
@ -93,11 +92,13 @@ xbps_rpool_init(struct xbps_handle *xhp)
|
||||
prop_object_release(d);
|
||||
goto out;
|
||||
}
|
||||
if (!xbps_add_obj_to_dict(d, array, "index")) {
|
||||
if (!prop_dictionary_set(d, "index", array)) {
|
||||
rv = EINVAL;
|
||||
prop_object_release(array);
|
||||
prop_object_release(d);
|
||||
goto out;
|
||||
}
|
||||
prop_object_release(array);
|
||||
if (!prop_array_add(xhp->repo_pool, d)) {
|
||||
rv = EINVAL;
|
||||
prop_object_release(d);
|
||||
@ -124,7 +125,6 @@ out:
|
||||
void HIDDEN
|
||||
xbps_rpool_release(struct xbps_handle *xhp)
|
||||
{
|
||||
prop_array_t idx;
|
||||
prop_dictionary_t d;
|
||||
size_t i;
|
||||
const char *uri;
|
||||
@ -134,15 +134,14 @@ 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");
|
||||
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);
|
||||
}
|
||||
prop_object_release(xhp->repo_pool);
|
||||
xhp->repo_pool = NULL;
|
||||
xbps_dbg_printf(xhp, "[rpool] released ok.\n");
|
||||
}
|
||||
|
@ -64,7 +64,8 @@ repo_find_virtualpkg_cb(struct xbps_handle *xhp,
|
||||
rpf->pattern);
|
||||
}
|
||||
if (rpf->pkgd) {
|
||||
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
|
||||
prop_dictionary_set_cstring_nocopy(rpf->pkgd,
|
||||
"repository", rpi->uri);
|
||||
*done = true;
|
||||
return 0;
|
||||
}
|
||||
@ -90,7 +91,8 @@ repo_find_virtualpkg_conf_cb(struct xbps_handle *xhp,
|
||||
rpi->repo, rpf->pattern);
|
||||
}
|
||||
if (rpf->pkgd) {
|
||||
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
|
||||
prop_dictionary_set_cstring_nocopy(rpf->pkgd,
|
||||
"repository", rpi->uri);
|
||||
*done = true;
|
||||
return 0;
|
||||
}
|
||||
@ -126,7 +128,8 @@ repo_find_pkg_cb(struct xbps_handle *xhp,
|
||||
* Package dictionary found, add the "repository"
|
||||
* object with the URI.
|
||||
*/
|
||||
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
|
||||
prop_dictionary_set_cstring_nocopy(rpf->pkgd,
|
||||
"repository", rpi->uri);
|
||||
*done = true;
|
||||
return 0;
|
||||
}
|
||||
@ -170,7 +173,8 @@ repo_find_best_pkg_cb(struct xbps_handle *xhp,
|
||||
"[rpool] Found best match '%s' (%s).\n",
|
||||
repopkgver, rpi->uri);
|
||||
rpf->pkgd = pkgd;
|
||||
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
|
||||
prop_dictionary_set_cstring_nocopy(rpf->pkgd,
|
||||
"repository", rpi->uri);
|
||||
rpf->bestpkgver = repopkgver;
|
||||
return 0;
|
||||
}
|
||||
@ -183,7 +187,8 @@ repo_find_best_pkg_cb(struct xbps_handle *xhp,
|
||||
"[rpool] Found best match '%s' (%s).\n",
|
||||
repopkgver, rpi->uri);
|
||||
rpf->pkgd = pkgd;
|
||||
prop_dictionary_set_cstring(rpf->pkgd, "repository", rpi->uri);
|
||||
prop_dictionary_set_cstring_nocopy(rpf->pkgd,
|
||||
"repository", rpi->uri);
|
||||
rpf->bestpkgver = repopkgver;
|
||||
}
|
||||
return 0;
|
||||
@ -250,7 +255,7 @@ repo_find_pkg(struct xbps_handle *xhp,
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return prop_dictionary_copy(rpf.pkgd);
|
||||
return rpf.pkgd;
|
||||
}
|
||||
|
||||
prop_dictionary_t
|
||||
|
@ -111,9 +111,6 @@ pkgdep_find_idx(const char *name, const char *trans)
|
||||
static void
|
||||
pkgdep_release(struct pkgdep *pd)
|
||||
{
|
||||
if (pd->d != NULL)
|
||||
prop_object_release(pd->d);
|
||||
|
||||
free(pd->name);
|
||||
free(pd);
|
||||
pd = NULL;
|
||||
@ -133,12 +130,9 @@ pkgdep_alloc(prop_dictionary_t d, const char *name, const char *trans)
|
||||
free(pd);
|
||||
return NULL;
|
||||
}
|
||||
if (d != NULL)
|
||||
pd->d = prop_dictionary_copy(d);
|
||||
else
|
||||
pd->d = NULL;
|
||||
|
||||
(void)strlcpy(pd->name, name, len);
|
||||
pd->d = d;
|
||||
memcpy(pd->name, name, len-1);
|
||||
pd->name[len-1] = '\0';
|
||||
pd->trans = trans;
|
||||
|
||||
return pd;
|
||||
@ -318,6 +312,7 @@ xbps_transaction_sort_pkg_deps(struct xbps_handle *xhp)
|
||||
unsorted = prop_dictionary_get(xhp->transd, "unsorted_deps");
|
||||
if (prop_array_count(unsorted) == 0) {
|
||||
prop_dictionary_set(xhp->transd, "packages", sorted);
|
||||
prop_object_release(sorted);
|
||||
return 0;
|
||||
}
|
||||
/*
|
||||
|
@ -150,7 +150,9 @@ xbps_pkg_name(const char *pkg)
|
||||
len = strlen(pkg) - strlen(p) + 1;
|
||||
buf = malloc(len);
|
||||
assert(buf != NULL);
|
||||
strlcpy(buf, pkg, len);
|
||||
|
||||
memcpy(buf, pkg, len-1);
|
||||
buf[len-1] = '\0';
|
||||
|
||||
return buf;
|
||||
}
|
||||
@ -172,7 +174,9 @@ xbps_pkgpattern_name(const char *pkg)
|
||||
|
||||
pkgname = malloc(len);
|
||||
assert(pkgname != NULL);
|
||||
strlcpy(pkgname, pkg, len);
|
||||
|
||||
memcpy(pkgname, pkg, len-1);
|
||||
pkgname[len-1] = '\0';
|
||||
|
||||
return pkgname;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user