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

Memory leak caused by a wrong optimization #370

Closed
vtereshkov opened this issue Mar 15, 2024 · 1 comment
Closed

Memory leak caused by a wrong optimization #370

vtereshkov opened this issue Mar 15, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@vtereshkov
Copy link
Owner

vtereshkov commented Mar 15, 2024

The temporary reference holder variable that stores the returned value of foo() has been eliminated because this returned value has been immediately (?) assigned to p. However, p is of type T, not V, so the b' s reference count is not tracked.

type T = struct {x: int}
type V = struct {a: T; b: []int}

fn foo(): V {
        return {{42}, {}}
}

fn main() {
        p := foo().a
        printf("%v\n", p)   // {x: 42}
        
}  // Warning: Memory leak
@vtereshkov vtereshkov added the bug Something isn't working label Mar 15, 2024
@vtereshkov vtereshkov changed the title Memory leak after discarding an std.Err result Memory leak after discarding a function result Mar 15, 2024
@vtereshkov vtereshkov changed the title Memory leak after discarding a function result Memory leak caused by a wrong optimization Mar 15, 2024
@vtereshkov
Copy link
Owner Author

000000040      9                    PUSH_ZERO 2
000000041      9               PUSH_LOCAL_PTR -40        // Result of type V
000000042      9                         CALL foo (1)
000000043      9                     PUSH_REG 0
000000044      9               PUSH_LOCAL_PTR -80
000000045      9                 SWAP; ASSIGN struct 8   // Assignment of type T

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant