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
91cebdccde
commit
304f9499cf
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