Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GeneralPurposeAllocator: No stack trace for memory leak on Windows #6687

Closed
lxn opened this issue Oct 15, 2020 · 4 comments · Fixed by #11885
Closed

GeneralPurposeAllocator: No stack trace for memory leak on Windows #6687

lxn opened this issue Oct 15, 2020 · 4 comments · Fixed by #11885
Labels
bug Observed behavior contradicts documented or intended behavior os-windows standard library This issue involves writing Zig code for the standard library.
Milestone

Comments

@lxn
Copy link

lxn commented Oct 15, 2020

The code below produces just the output Memory leak detected: on Windows, missing the stack trace.

const std = @import("std");

pub fn main() anyerror!void {
    var gpa = std.heap.GeneralPurposeAllocator(.{}){};
    defer _ = gpa.deinit();
    const allocator = &gpa.allocator;

    _ = try allocator.alloc(u8, 1);
}
@andrewrk andrewrk added bug Observed behavior contradicts documented or intended behavior os-windows standard library This issue involves writing Zig code for the standard library. labels Oct 17, 2020
@andrewrk andrewrk added this to the 0.8.0 milestone Oct 17, 2020
@andrewrk andrewrk modified the milestones: 0.8.0, 0.9.0 Nov 6, 2020
@andrewrk andrewrk modified the milestones: 0.9.0, 0.10.0 May 19, 2021
@nektro
Copy link
Contributor

nektro commented Jun 13, 2022

example of the intended output from linux

$ zig run test.zig 
error(gpa): memory address 0x7f801f995000 leaked: 
./test.zig:8:28: 0x22826e in main (test)
    _ = try allocator.alloc(u8, 1);
                           ^
/home/meg/.local/share/zig/lib/std/start.zig:581:37: 0x22195a in std.start.callMain (test)
            const result = root.main() catch |err| {
                                    ^
/home/meg/.local/share/zig/lib/std/start.zig:515:12: 0x20880e in std.start.callMainWithArgs (test)
    return @call(.{ .modifier = .always_inline }, callMain, .{});
           ^
/home/meg/.local/share/zig/lib/std/start.zig:425:17: 0x2076e6 in std.start.posixCallMainAndExit (test)
    std.os.exit(@call(.{ .modifier = .always_inline }, callMainWithArgs, .{ argc, argv, envp }));
                ^

@nekrondev
Copy link

I always run into this when developing for my company (windows based infrastructure) and have to do the debugging of memory leaks on some Linux based server.

So why is the output of the memory trace invisible for windows? Is the output piped to wrong fd?

@svc-user
Copy link

Upon initializing the GeneralPurposeAllocator you can set the stack_trace_frames field of the config to iirc at least 32 on windows to get a stack trace. As a workaround,ofc.

squeek502 added a commit to squeek502/zig that referenced this issue Jun 18, 2022
Before this commit, the passed in length would always be given to the RtlCaptureStackBackTrace call. Now we always give the length of the actual buffer we're using (the addr_buf_stack size of 32 or the passed in length if it's larger than 32; this matches what the doc comment says the function was meant to be doing as well).

This was causing empty stack traces for things like the GeneralPurposeAllocator leak checking.

Fixes ziglang#6687
squeek502 added a commit to squeek502/zig that referenced this issue Jun 18, 2022
Before this commit, the passed in length would always be given to the RtlCaptureStackBackTrace call. Now we always give the length of the actual buffer we're using (the addr_buf_stack size of 32 or the passed in length if it's larger than 32; this matches what the doc comment says the function was meant to be doing as well).

This was causing empty stack traces for things like the GeneralPurposeAllocator leak checking.

Fixes ziglang#6687
@squeek502
Copy link
Collaborator

Upon initializing the GeneralPurposeAllocator you can set the stack_trace_frames field of the config to iirc at least 32 on windows to get a stack trace. As a workaround,ofc.

Thanks for mentioning this, made it much easier to figure out what was going wrong (#11885).

squeek502 added a commit to squeek502/zig that referenced this issue Jun 18, 2022
Before this commit, the passed in length would always be given to the RtlCaptureStackBackTrace call. Now we always give the length of the actual buffer we're using (the addr_buf_stack size of 32 or the passed in length if it's larger than 32; this matches what the doc comment says the function was meant to be doing as well).

This was causing empty stack traces for things like the GeneralPurposeAllocator leak checking.

Fixes ziglang#6687
Vexu pushed a commit that referenced this issue Jun 27, 2022
Before this commit, the passed in length would always be given to the RtlCaptureStackBackTrace call. Now we always give the length of the actual buffer we're using (the addr_buf_stack size of 32 or the passed in length if it's larger than 32; this matches what the doc comment says the function was meant to be doing as well).

This was causing empty stack traces for things like the GeneralPurposeAllocator leak checking.

Fixes #6687
@andrewrk andrewrk modified the milestones: 0.12.0, 0.10.0 Jun 28, 2022
andrewrk pushed a commit that referenced this issue Jul 19, 2022
Before this commit, the passed in length would always be given to the RtlCaptureStackBackTrace call. Now we always give the length of the actual buffer we're using (the addr_buf_stack size of 32 or the passed in length if it's larger than 32; this matches what the doc comment says the function was meant to be doing as well).

This was causing empty stack traces for things like the GeneralPurposeAllocator leak checking.

Fixes #6687
wooster0 pushed a commit to wooster0/zig that referenced this issue Jul 24, 2022
Before this commit, the passed in length would always be given to the RtlCaptureStackBackTrace call. Now we always give the length of the actual buffer we're using (the addr_buf_stack size of 32 or the passed in length if it's larger than 32; this matches what the doc comment says the function was meant to be doing as well).

This was causing empty stack traces for things like the GeneralPurposeAllocator leak checking.

Fixes ziglang#6687
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Observed behavior contradicts documented or intended behavior os-windows standard library This issue involves writing Zig code for the standard library.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants