Skip to content

Commit 6b2b514

Browse files
cataphractclaude
andcommitted
Always call archive_write_finish_entry even when copy_data fails
If copy_data throws and returns early, archive_write_finish_entry was skipped, leaving the file handle open. On Windows this blocks unlink() in the test cleanup. Call finish_entry unconditionally after archive_write_header succeeds, then return if copy_data had failed. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 2b10439 commit 6b2b514

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

libarchive.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,11 +331,15 @@ PHP_METHOD(libarchive_Archive, extractCurrent)
331331
return;
332332
}
333333

334-
if (!copy_data(arch_obj->archive, arch_obj->arch_disk)) {
335-
return;
336-
}
334+
bool data_ok = copy_data(arch_obj->archive, arch_obj->arch_disk);
337335

336+
/* Always finish the entry to close the file handle, even if copy_data
337+
* failed — otherwise the handle stays open until the object is freed,
338+
* blocking unlink() on Windows. */
338339
res = archive_write_finish_entry(arch_obj->arch_disk);
340+
if (!data_ok) {
341+
return;
342+
}
339343
if (res != ARCHIVE_OK) {
340344
zend_throw_exception_ex(except_ce, archive_errno(arch_obj->arch_disk),
341345
"Could not finish writing entry: %s",

0 commit comments

Comments
 (0)