Skip to content

Commit

Permalink
imports: fix panic when error causes closure of nil system
Browse files Browse the repository at this point in the history
Signed-off-by: Achille Roussel <[email protected]>
  • Loading branch information
achille-roussel committed Jun 26, 2023
1 parent 67717ce commit bfe9c24
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions imports/builder_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import (

// Instantiate compiles and instantiates the WASI module and binds it to
// the specified context.
func (b *Builder) Instantiate(ctx context.Context, runtime wazero.Runtime) (ctxret context.Context, system wasi.System, err error) {
func (b *Builder) Instantiate(ctx context.Context, runtime wazero.Runtime) (ctxret context.Context, sys wasi.System, err error) {
if len(b.errors) > 0 {
return ctx, nil, errors.Join(b.errors...)
}
Expand Down Expand Up @@ -80,9 +80,9 @@ func (b *Builder) Instantiate(ctx context.Context, runtime wazero.Runtime) (ctxr
Rand: rand,
Exit: exit,
}
system = unixSystem
system := wasi.System(unixSystem)
defer func() {
if err != nil {
if system != nil {
system.Close(context.Background())
}
}()
Expand Down Expand Up @@ -187,7 +187,9 @@ func (b *Builder) Instantiate(ctx context.Context, runtime wazero.Runtime) (ctxr
)

ctx = wazergo.WithModuleInstance(ctx, instance)
return ctx, system, nil
sys = system
system = nil
return ctx, sys, nil
}

func dup(fd int) (int, error) {
Expand Down

0 comments on commit bfe9c24

Please sign in to comment.