]> Cypherpunks repositories - gostls13.git/commit
os/user: allocate buffers in Go memory, not C memory
authorIan Lance Taylor <iant@golang.org>
Thu, 10 Nov 2022 04:55:17 +0000 (20:55 -0800)
committerGopher Robot <gobot@golang.org>
Thu, 10 Nov 2022 05:54:51 +0000 (05:54 +0000)
commitc3d444d09852981daa6ed9e0ba65d90c89a7d917
tree4402a207b611c92685c72226b23b9ef15fb6a493
parentd2aa787f2a925a97dad11b1acb2a065f52b097f8
os/user: allocate buffers in Go memory, not C memory

Since the first implementation of os/user, it's called C malloc
to allocate memory for buffers. However, the buffers are just
used for temporary storage, and we can just a []byte instead.

To make this work without causing cgo pointer errors, we move
the pwd and grp structs into C stack memory, and just return them.
It's OK to store a Go pointer on the C stack temporarily.

Change-Id: I9f8ffb6e51df1e585276c259fe99359d7835df87
Reviewed-on: https://go-review.googlesource.com/c/go/+/449335
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
src/os/user/cgo_lookup_unix.go