runtime/cgo: fix unsetenv wrapper

The wrapper takes a pointer to the argument, not the argument itself.

Fixes #36705

Change-Id: I566d4457d00bf5b84e4a8315a26516975f0d7e10
Reviewed-on: https://go-review.googlesource.com/c/go/+/215942
Run-TryBot: Keith Randall <khr@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Ian Lance Taylor <iant@golang.org>
This commit is contained in:
Keith Randall 2020-01-22 20:48:21 -08:00
parent 28c501b7b3
commit 4f074b58d2
2 changed files with 29 additions and 2 deletions

View File

@ -20,9 +20,9 @@ x_cgo_setenv(char **arg)
/* Stub for calling unsetenv */
void
x_cgo_unsetenv(char *arg)
x_cgo_unsetenv(char **arg)
{
_cgo_tsan_acquire();
unsetenv(arg);
unsetenv(arg[0]);
_cgo_tsan_release();
}

View File

@ -0,0 +1,27 @@
// +build cgo
// run
// Copyright 2020 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// #include <stdlib.h>
// #include <unistd.h>
import "C"
import "os"
func main() {
os.Setenv("FOO", "bar")
s := C.GoString(C.getenv(C.CString("FOO")))
if s != "bar" {
panic("bad setenv, environment variable only has value \"" + s + "\"")
}
os.Unsetenv("FOO")
s = C.GoString(C.getenv(C.CString("FOO")))
if s != "" {
panic("bad unsetenv, environment variable still has value \"" + s + "\"")
}
}