xbps_unpack_binary_pkg: fix a memleak and make all error paths go to a single point.

This commit is contained in:
Juan RP 2010-12-25 02:38:30 +01:00
parent 71878669da
commit d307226ee7

View File

@ -245,8 +245,10 @@ unpack_archive_fini(struct archive *ar,
archive_entry_set_pathname(entry, buf); archive_entry_set_pathname(entry, buf);
free(buf); free(buf);
if (archive_read_extract(ar, entry, lflags) != 0) if (archive_read_extract(ar, entry, lflags) != 0) {
return archive_errno(ar); rv = archive_errno(ar);
goto out;
}
propsd = propsd =
xbps_get_pkg_dict_from_metadata_plist(pkgname, xbps_get_pkg_dict_from_metadata_plist(pkgname,
@ -287,10 +289,9 @@ unpack_archive_fini(struct archive *ar,
*/ */
if (prop_dictionary_get(propsd, "conf_files")) { if (prop_dictionary_get(propsd, "conf_files")) {
if ((rv = xbps_config_file_from_archive_entry(filesd, if ((rv = xbps_config_file_from_archive_entry(filesd,
propsd, entry, &lflags, &skip_entry)) != 0) { propsd, entry, &lflags, &skip_entry)) != 0)
prop_object_release(filesd);
goto out; goto out;
}
if (skip_entry) { if (skip_entry) {
archive_read_data_skip(ar); archive_read_data_skip(ar);
skip_entry = false; skip_entry = false;
@ -351,8 +352,8 @@ unpack_archive_fini(struct archive *ar,
buf = xbps_xasprintf(".%s/metadata/%s/%s", buf = xbps_xasprintf(".%s/metadata/%s/%s",
XBPS_META_PATH, pkgname, XBPS_PKGFILES); XBPS_META_PATH, pkgname, XBPS_PKGFILES);
if (buf == NULL) { if (buf == NULL) {
prop_object_release(filesd); rv = ENOMEM;
return ENOMEM; goto out;
} }
/* /*
* Check if files.plist exists and pkg is NOT marked as * Check if files.plist exists and pkg is NOT marked as
@ -366,14 +367,16 @@ unpack_archive_fini(struct archive *ar,
rv = xbps_remove_obsoletes(old_filesd, filesd); rv = xbps_remove_obsoletes(old_filesd, filesd);
if (rv != 0) { if (rv != 0) {
prop_object_release(old_filesd); prop_object_release(old_filesd);
prop_object_release(filesd);
free(buf); free(buf);
return rv; rv = errno;
goto out;
} }
prop_object_release(old_filesd);
} else if (errno && errno != ENOENT) { } else if (errno && errno != ENOENT) {
prop_object_release(filesd);
free(buf); free(buf);
return errno; rv = errno;
goto out;
} }
} }
/* /*
@ -382,9 +385,9 @@ unpack_archive_fini(struct archive *ar,
* is reachable. * is reachable.
*/ */
if (!prop_dictionary_externalize_to_zfile(filesd, buf)) { if (!prop_dictionary_externalize_to_zfile(filesd, buf)) {
prop_object_release(filesd);
free(buf); free(buf);
return errno; rv = errno;
goto out;
} }
free(buf); free(buf);
} }