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 from frame.toBytes() #54

Open
Froxcey opened this issue Nov 2, 2024 · 2 comments
Open

Memory leak from frame.toBytes() #54

Froxcey opened this issue Nov 2, 2024 · 2 comments

Comments

@Froxcey
Copy link

Froxcey commented Nov 2, 2024

In my code base, I'm calling mat.toByte() every frame
Since that function allocates memory on heap, it causes memory leak
Is there a way to do something like

var bytes = mat.toBytes();
defer mat.freeBytes();
@Froxcey
Copy link
Author

Froxcey commented Nov 2, 2024

I found the fix, just need to do

pub fn toBytes(self: Self) []u8 {
    var p: c.struct_ByteArray = c.Mat_ToBytes(self.ptr);
+   defer c.free(p.data);

    const len = @as(usize, @intCast(p.length));
    return p.data[0..len];
}

in src/core/mat.zig

zig-nominated-compat@8076f26

@Froxcey Froxcey changed the title Deallocate frame.toBytes() Memory leak from frame.toBytes() Feb 9, 2025
@ryoppippi
Copy link
Owner

@Froxcey I didn't notice this one! send me PR!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants