Skip to content

cmd/cgo: FreeLibrary a go c-shared dll make app crash #32497

@nowind

Description

@nowind

What version of Go are you using (go version)?

$ go version
go version go1.12.5 windows/386

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
set GOARCH=386
set GOBIN=
set GOCACHE=C:\Users\nowind\AppData\Local\go-build
set GOEXE=.exe
set GOFLAGS=
set GOHOSTARCH=386
set GOHOSTOS=windows
set GOOS=windows
set GOPATH=E:\tools\go\user
set GOPROXY=https://goproxy.io
set GORACE=
set GOROOT=E:\tools\go386
set GOTMPDIR=
set GOTOOLDIR=E:\tools\go386\pkg\tool\windows_386
set GCCGO=gccgo
set GO386=sse2
set CC=gcc
set CXX=g++
set CGO_ENABLED=1
set GOMOD=NUL
set CGO_CFLAGS=-g -O2
set CGO_CPPFLAGS=
set CGO_CXXFLAGS=-g -O2
set CGO_FFLAGS=-g -O2
set CGO_LDFLAGS=-g -O2
set PKG_CONFIG=pkg-config
set GOGCCFLAGS=-m32 -mthreads -fmessage-length=0 -fdebug-prefix-map=C:\Users\now
ind\AppData\Local\Temp\go-build636168646=/tmp/go-build -gno-record-gcc-switches

What did you do?

dll.go:

package main

import (
	"C"
	"fmt"
)

//export SayHi
func SayHi() {
	fmt.Println("Hi, I'm go dll")
}

func main() {
}

dll.c

int main(int argc, char* argv[])
{
	HMODULE dll= ::LoadLibrary("dll.dll");
	if(dll==NULL)
	{
		printf("err!\n");
		return -1;
	}
       getchar();
	::FreeLibrary(dll);
        getchar();
	return 0;
}

What did you expect to see?

What did you see instead?

after call FreeLibrary ,app crash ,but no error messagebox

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.OS-Windowscompiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions