be_package: delay freeing archive resource

The error path uconditinally tries to free the archive, leading to a
double-free segmentation fault if the error path is triggered after
already freeing it.

Signed-off-by: Andrew Gregory <andrew.gregory.8@gmail.com>
This commit is contained in:
Andrew Gregory 2024-02-04 12:21:11 -08:00 committed by Allan McRae
parent edd57c8b96
commit fde59b99e8

View file

@ -652,8 +652,6 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
goto pkg_invalid; goto pkg_invalid;
} }
_alpm_archive_read_free(archive);
/* internal fields for package struct */ /* internal fields for package struct */
newpkg->origin = ALPM_PKG_FROM_FILE; newpkg->origin = ALPM_PKG_FROM_FILE;
STRDUP(newpkg->origin_data.file, pkgfile, goto error); STRDUP(newpkg->origin_data.file, pkgfile, goto error);
@ -675,6 +673,7 @@ alpm_pkg_t *_alpm_pkg_load_internal(alpm_handle_t *handle,
newpkg->infolevel |= INFRQ_FILES; newpkg->infolevel |= INFRQ_FILES;
} }
_alpm_archive_read_free(archive);
close(fd); close(fd);
return newpkg; return newpkg;