mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-23 12:31:07 +01:00
lib/bytesutil: prevent from garbage collecting s before returning from ToUnsafeBytes
This commit is contained in:
parent
f2b04f2efe
commit
937338abdf
@ -2,6 +2,7 @@ package bytesutil
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"runtime"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
@ -29,5 +30,7 @@ func ToUnsafeBytes(s string) []byte {
|
||||
slh.Data = sh.Data
|
||||
slh.Len = sh.Len
|
||||
slh.Cap = sh.Len
|
||||
return *(*[]byte)(unsafe.Pointer(&slh))
|
||||
b := *(*[]byte)(unsafe.Pointer(&slh))
|
||||
runtime.KeepAlive(s)
|
||||
return b
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user