Skip to content

emit-c: map keys and values are never dropped (clear, remove and scope exit leak owning elements) #1192

Closed

Description

@ehartford

The C backend emits with_hashmap_clear / with_hashmap_remove with no element drops and never frees a map's keys or values (src/CCodegen.w ~6407, ~6908; no with_hashmap_free, no slot walk). The LLVM backend walks live slots with the receiver's sema type before clear and at scope exit (mir_emit_hash_collection_element_drops), and since #1189 transports the stored key out of remove and drops it. With an owning key or value type (HashMap[str, str]) emit-c output leaks every element.

Found while fixing #1189; not changed there. Related: emit-c already fails loudly for values()/items() and for map traversal (D44).

Activity

  1. ehartford commented on Oct 25, 2026

    @ehartford
    ContributorAuthor

    Triage 2026-10-25, with v0.15.3.0 (main a261b65): reproduced in source. The C backend's map.clear (src/CCodegen.w:7782-7789) emits with_hashmap_clear(...) with no walk of the live slots, and no with_hashmap_free or element drop appears anywhere in src/CCodegen.w.

    post-release: part of the emit-C lane campaign (#955).

  2. added this to the post-v0.16.0 milestone on Oct 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions