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

@@ -57,12 +57,7 @@ xbps_repo_path(struct xbps_handle *xhp, const char *url)
static xbps_dictionary_t
repo_get_dict(struct xbps_repo *repo)
{
xbps_dictionary_t d = NULL;
struct archive_entry *entry;
char *adata = NULL;
const void *buf;
off_t offset;
size_t size;
int rv;
if (repo->ar == NULL)
@@ -75,35 +70,7 @@ repo_get_dict(struct xbps_repo *repo)
archive_error_string(repo->ar));
return NULL;
}
for (;;) {
rv = archive_read_data_block(repo->ar, &buf, &size, &offset);
if (rv == ARCHIVE_EOF)
break;
if (rv != ARCHIVE_OK) {
if (adata != NULL)
free(adata);
xbps_dbg_printf(repo->xhp,
"%s: read_data_block %s\n", repo->uri,
archive_error_string(repo->ar));
return NULL;
}
if (adata == NULL) {
adata = malloc(size);
} else {
adata = realloc(adata, size+offset);
if (adata == NULL) {
free(adata);
return NULL;
}
}
memcpy(adata+offset, buf, size);
}
if (adata != NULL) {
d = xbps_dictionary_internalize(adata);
free(adata);
}
return d;
return xbps_archive_get_dictionary(repo->ar, entry);
}
static bool
@@ -304,7 +271,6 @@ xbps_repo_close(struct xbps_repo *repo, bool lock)
xbps_dbg_printf(repo->xhp, "[repo] failed to unlock %s: %s\n", repo->uri, strerror(errno));
close(repo->fd);
free(repo);
}
xbps_dictionary_t