"invalid" in this case simply means files that may or may not be
archives. Discovered via a `pacman -Sc` operation with delta files in
the package cache directory, but can be triggered if any file is passed
to `pacman -Ql` that isn't an archive, for instance, or if the sync
database file is not an archive.
Fix it up so we are more careful about calling archive_read_finish()
only on archives that are valid and have not already been closed, and
teach our archive open function to set the returned archive to NULL if
we aren't going to be returning something valid anyway.
diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
index 2cce824..e2cbd8c 100644
--- a/lib/libalpm/util.c
+++ b/lib/libalpm/util.c
@@ -213,6 +213,8 @@ size_t _alpm_strip_newline(char *str)
* This takes care of creating the libarchive 'archive' struct, setting up
* compression and format options, opening a file descriptor, setting up the
* buffer size, and performing a stat on the path once opened.
+ * On error, no file descriptor is opened, and the archive pointer returned
+ * will be set to NULL.
* @param handle the context handle
* @param path the path of the archive to open
* @param buf space for a stat buffer for the given path
@@ -238,16 +240,13 @@ int _alpm_open_archive(alpm_handle_t *handle, const char *path,
if(fd < 0) {
_alpm_log(handle, ALPM_LOG_ERROR,
_("could not open file %s: %s
"), path, strerror(errno));
- archive_read_finish(*archive);
- RET_ERR(handle, error, -1);
+ goto error;
}