Improve xbps_end() and use it before exit(3)ing.

- Simplify xbps_repo_open::repo_get_dict().
- Use xbps_end() in the utils where necessary.
- Make xbps_end() call xbps_pkgdb_unlock() if necessary.
- Make xbps_end() release rpool resources.
- Make xbps_end() release resources from xbps_handle.
- Fixed 90% of reported leaks (still reachable at exit) from valgrind.

That was to silence valgrind's memcheck with --leak-check=full.
This commit is contained in:
Juan RP
2015-01-10 19:11:31 +01:00
parent d98442d84e
commit ee175a2a68
11 changed files with 50 additions and 55 deletions

View File

@ -109,11 +109,13 @@ xbps_pkgdb_unlock(struct xbps_handle *xhp)
{
(void)xbps_pkgdb_update(xhp, true);
if (lockf(pkgdb_fd, F_ULOCK, 0) == -1)
xbps_dbg_printf(xhp, "[pkgdb] failed to unlock pkgdb: %s\n", strerror(errno));
if (pkgdb_fd != -1) {
if (lockf(pkgdb_fd, F_ULOCK, 0) == -1)
xbps_dbg_printf(xhp, "[pkgdb] failed to unlock pkgdb: %s\n", strerror(errno));
(void)close(pkgdb_fd);
pkgdb_fd = -1;
(void)close(pkgdb_fd);
pkgdb_fd = -1;
}
}
static int
@ -247,8 +249,15 @@ xbps_pkgdb_release(struct xbps_handle *xhp)
if (xhp->pkgdb == NULL)
return;
if (xhp->pkgdb_revdeps)
xbps_object_release(xhp->pkgdb_revdeps);
if (xhp->vpkgd)
xbps_object_release(xhp->vpkgd);
if (xhp->preserved_files)
xbps_object_release(xhp->preserved_files);
xbps_pkgdb_unlock(xhp);
xbps_object_release(xhp->pkgdb);
xhp->pkgdb = NULL;
xbps_dbg_printf(xhp, "[pkgdb] released ok.\n");
}