From 98c4caac68b4ccdf3d5f4909b819ff8c3c06c720 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Wed, 4 Mar 2026 13:16:50 +0800 Subject: [PATCH] =?UTF-8?q?```=20fix(socket):=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=BA=8B=E4=BB=B6=E5=A4=84=E7=90=86?= =?UTF-8?q?=E4=B8=AD=E7=9A=84=E6=95=B0=E6=8D=AE=E5=BC=95=E7=94=A8=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 解决切片共享底层数据导致的潜在内存安全问题,通过深拷贝确保数据独立性, 避免并发访问时的数据竞争风险。 ``` --- common/socket/ServerEvent.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/common/socket/ServerEvent.go b/common/socket/ServerEvent.go index bee984e1f..df0814024 100644 --- a/common/socket/ServerEvent.go +++ b/common/socket/ServerEvent.go @@ -279,7 +279,8 @@ func (s *Server) onevent(c gnet.Conn, v []byte) { // 解析数据部分(17字节之后) // 数据部分:直接引用切片,避免 make if len(v) > 17 { - header.Data = v[17:] + header.Data = make([]byte, len(v[17:])) + copy(header.Data, v[17:]) // 核心修改:拷贝数据 } else { header.Data = nil // 避免空切片分配 }