Skip to content

fix: ghostty_surface_inherited_config returns dangling working_directory pointer #181

@daiimus

Description

@daiimus

Summary

ghostty_surface_inherited_config (embedded.zig:1044-1061) allocates a dupeZ of the working directory via the app allocator, then returns the Options struct by value. The C header declares ghostty_surface_config_s containing const char* working_directory.

The caller receives a raw pointer to heap memory with:

  • No documented ownership
  • No free function
  • No indication that the caller must free it

This is a memory leak if the caller doesn't free it, or a use-after-free if the caller incorrectly frees it with the wrong allocator.

Fix

Either:

  1. Document the ownership and provide a ghostty_surface_config_free function.
  2. Use a static/arena-allocated string with clear lifetime semantics.

Severity

MEDIUM — Memory leak per call. Not a crash but accumulates.

Source

Identified during code review of daiimus/ghostty:ios-external-backend.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingp2-mediumDegraded experience, workaround existsupstreamBug exists in upstream ghosttyzig-forkRequires Ghostty fork changes

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions