Skip to content

Conversation

@forketyfork
Copy link
Owner

Summary

Fixes double-free bugs in openUrl identified by a reviewer on PR #191.

Problem

The openUrl function had two double-free bugs:

  1. When dupe failed, manual destroy(ctx) was called before returning the error, but the errdefer on line 34 would also trigger on error return
  2. When Thread.spawn failed, ctx.deinit() freed both url and ctx, then returning an error triggered both errdefer statements

Solution

Remove the manual cleanup calls in catch blocks. The errdefer mechanism exists precisely for this purpose — to ensure cleanup happens exactly once when returning an error. Let errdefer do its job.

Test plan

  • zig build passes
  • zig build test passes

Issue: A reviewer identified that the openUrl function contained double-free
bugs where manual cleanup was performed before returning an error, but the
registered errdefer statements would also execute on error return.

Solution: Remove manual cleanup calls (destroy and deinit) in catch blocks
since returning an error already triggers the errdefer cleanup handlers.
The errdefer mechanism exists precisely for this purpose - to ensure cleanup
happens exactly once when returning an error.
@forketyfork forketyfork merged commit f4816a1 into main Feb 3, 2026
4 checks passed
@forketyfork forketyfork deleted the fix/double-free-openurl branch February 3, 2026 16:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant