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 #23

Open
brucekim opened this issue Oct 27, 2021 · 2 comments
Open

memory leak #23

brucekim opened this issue Oct 27, 2021 · 2 comments

Comments

@brucekim
Copy link
Collaborator

Hi,

I am checking memory allocation & release with debug/pprof tool.

And I found that heap profiler indicates following heap stack.

0: 0 [2: 48] @ 0x4613e53 0x45e5fe9 0x481deb1 0x4076681
#	0x4613e52	github.com/tinyzimmer/go-gst/gst.NewBufferFromBytes.func1+0x52	/Users/bkim/go/pkg/mod/github.com/tinyzimmer/[email protected]/gst/gst_buffer.go:101
#	0x45e5fe8	github.com/tinyzimmer/go-gst/gst.NewBufferFromBytes+0x48	/Users/bkim/go/pkg/mod/github.com/tinyzimmer/[email protected]/gst/gst_buffer.go:101

This is because Extract() returns C.GoBytes() which underlying array is a copy of the array in C area.
And I couldn't find anywhere doing free for it.

Please help me whether or not I have right understanding.

go-gst/gst/gst_buffer.go

Lines 387 to 394 in 5437f8a

// Extract extracts size bytes starting from offset in this buffer. The data extracted may be lower
// than the actual size if the buffer did not contain enough data.
func (b *Buffer) Extract(offset, size int64) []byte {
dest := C.malloc(C.sizeof_char * C.gsize(size))
defer C.free(dest)
C.gst_buffer_extract(b.Instance(), C.gsize(offset), (C.gpointer)(unsafe.Pointer(dest)), C.gsize(size))
return C.GoBytes(dest, C.int(size))
}

@tinyzimmer
Copy link
Owner

I would expect the defer C.free(dest) to be taking care of it, but this is an interesting case indeed. Will warrant a closer look.

@RSWilli
Copy link

RSWilli commented Aug 24, 2023

@brucekim move this issue to https://github.com/go-gst/go-gst (where future development of the bindings will take place) if it is still necessary

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

3 participants