mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-11 19:04:08 +00:00
fix(windows): release FFmpeg memory and capture native crashes
This commit is contained in:
1 parent
89dfbe4c45
commit
89bd3f3af0
17 files changed
+486
-17
No files matched your search
@@ -0,0 +1,32 @@
|
||||
package ffmpeg
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
|
||||
"github.com/tetratelabs/wazero/experimental"
|
||||
)
|
||||
|
||||
// The runtime does not always invoke Free when a module's start function traps.
|
||||
// Keep host ownership until execution returns, including failed instantiation.
|
||||
func withOwnedMemory(ctx context.Context, allocator experimental.MemoryAllocator) (context.Context, func()) {
|
||||
var memories []*ownedLinearMemory
|
||||
ctx = experimental.WithMemoryAllocator(ctx, experimental.MemoryAllocatorFunc(
|
||||
func(cap, max uint64) experimental.LinearMemory {
|
||||
memory := &ownedLinearMemory{LinearMemory: allocator.Allocate(cap, max)}
|
||||
memories = append(memories, memory)
|
||||
return memory
|
||||
}))
|
||||
return ctx, func() {
|
||||
for _, memory := range memories {
|
||||
memory.Free()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type ownedLinearMemory struct {
|
||||
experimental.LinearMemory
|
||||
once sync.Once
|
||||
}
|
||||
|
||||
func (m *ownedLinearMemory) Free() { m.once.Do(m.LinearMemory.Free) }
|
||||
Reference in new issue
Block a user