mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2024-11-21 14:44:00 +00:00
lib/bytesutil: prevent from garbage collecting s before returning from ToUnsafeBytes
This commit is contained in:
parent
f2b04f2efe
commit
937338abdf
1 changed files with 4 additions and 1 deletions
|
@ -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 a new issue