Skip to content

memory safety when use-after-free occurs of a local function stack variable #3180

Description

@jrmuizel

The following program builds and runs without complaint. Is there the intent to detect UAFs or should one expect memory safety similar to C?

const std = @import("std");

const P = struct {
    id: u32,
};

pub fn main() !void {
    const alloc = std.heap.page_allocator;
    const k = try alloc.create(P);
    k.id = 5;
    alloc.destroy(k);
    const m = try alloc.create(P);
    std.debug.print("value: {}\n", .{k.id});
}

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementSolving this issue will likely involve adding new logic or components to the codebase.frontendTokenization, parsing, AstGen, Sema, and Liveness.

    Type

    No type

    Projects

    • Status
      To do

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions