mirror of
https://github.com/golang/go
synced 2024-11-16 20:04:52 -07:00
net: clear malloc'ed memory in cgoResSearch
For #61666 Change-Id: I7a0a849fba0abebe28804bdd6d364b154456e399 Reviewed-on: https://go-review.googlesource.com/c/go/+/534516 Run-TryBot: Ian Lance Taylor <iant@golang.org> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Damien Neil <dneil@google.com> Auto-Submit: Ian Lance Taylor <iant@google.com> Reviewed-by: Ian Lance Taylor <iant@google.com>
This commit is contained in:
parent
655155d0a7
commit
3b0fc5a51f
@ -319,8 +319,15 @@ func cgoResSearch(hostname string, rtype, class int) ([]dnsmessage.Resource, err
|
||||
acquireThread()
|
||||
defer releaseThread()
|
||||
|
||||
state := (*_C_struct___res_state)(_C_malloc(unsafe.Sizeof(_C_struct___res_state{})))
|
||||
defer _C_free(unsafe.Pointer(state))
|
||||
resStateSize := unsafe.Sizeof(_C_struct___res_state{})
|
||||
var state *_C_struct___res_state
|
||||
if resStateSize > 0 {
|
||||
mem := _C_malloc(resStateSize)
|
||||
defer _C_free(mem)
|
||||
memSlice := unsafe.Slice((*byte)(mem), resStateSize)
|
||||
clear(memSlice)
|
||||
state = (*_C_struct___res_state)(unsafe.Pointer(&memSlice[0]))
|
||||
}
|
||||
if err := _C_res_ninit(state); err != nil {
|
||||
return nil, errors.New("res_ninit failure: " + err.Error())
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user