diff --git a/patcher.go b/patcher.go index 192f410..5d259a0 100644 --- a/patcher.go +++ b/patcher.go @@ -113,6 +113,8 @@ func (p *Patch) Unpatch() error { } func isPatchable(target, redirection *reflect.Value) error { + patchLock.Lock() + defer patchLock.Unlock() if target.Kind() != reflect.Func || redirection.Kind() != reflect.Func { return errors.New("the target and/or redirection is not a Func") } diff --git a/patcher_test.go b/patcher_test.go index 5299a99..dcce394 100644 --- a/patcher_test.go +++ b/patcher_test.go @@ -2,9 +2,7 @@ package mpatch import ( "reflect" - "runtime" "testing" - "time" ) //go:noinline @@ -136,44 +134,3 @@ func TestInstanceValuePatcher(t *testing.T) { t.Fatal("The unpatch did not work") } } - -var slice []int - -//go:noinline -func TestGarbageCollectorExperiment(t *testing.T) { - - for i := 0; i < 10000000; i++ { - slice = append(slice, i) - } - go func() { - var sl []int - for i := 0; i < 10000000; i++ { - sl = append(slice, i) - } - _ = sl - }() - <-time.After(time.Second) - - aVal := methodA - ptr01 := reflect.ValueOf(aVal).Pointer() - slice = nil - runtime.GC() - for i := 0; i < 10000000; i++ { - slice = append(slice, i) - } - go func() { - var sl []int - for i := 0; i < 10000000; i++ { - sl = append(slice, i) - } - _ = sl - }() - <-time.After(time.Second) - slice = nil - runtime.GC() - ptr02 := reflect.ValueOf(aVal).Pointer() - - if ptr01 != ptr02 { - t.Fail() - } -}