Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto/sha256: memory leak or issue with heap profiler #30249

ebuchman opened this issue Feb 15, 2019 · 4 comments

crypto/sha256: memory leak or issue with heap profiler #30249

ebuchman opened this issue Feb 15, 2019 · 4 comments


Copy link

@ebuchman ebuchman commented Feb 15, 2019

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

$ go version
go version go1.11.5 darwin/amd64

Does this issue reproduce with the latest release?

Yes (1.11.5)

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

go env Output
$ go env

What did you do?

package main

import (
	_ "net/http/pprof"

func main() {
	runtime.MemProfileRate = 1
	fmt.Println(http.ListenAndServe("localhost:7070", nil))

func myFunc() {

Then check heap profile: http://localhost:7070/debug/pprof/heap?debug=1

What did you expect to see?

No entry for myFunc

What did you see instead?

0: 0 [1: 128] @ 0x107563d 0x1300102 0x1300061 0x102ee57 0x105ca71
#	0x107563c	crypto/sha256.New+0x2c	/Users/myuser/goRoot/1.11.5/src/crypto/sha256/sha256.go:181
#	0x1300101	main.myFunc+0x21	/Users/myuser/goApps/src/
#	0x1300060	main.main+0x30		/Users/myuser/goApps/src/
#	0x102ee56	runtime.main+0x206	/Users/myuser/goRoot/1.11.5/src/runtime/proc.go:201

Note this issue also holds for sha512, but not for sha1, and not for ripemd160 from x/crypto

@FiloSottile FiloSottile changed the title sha256: memory leak or issue with heap profiler crypto/sha256: memory leak or issue with heap profiler Feb 15, 2019
@FiloSottile FiloSottile added this to the Go1.13 milestone Feb 15, 2019
Copy link

@odeke-em odeke-em commented Feb 17, 2019

Thank you for filing this issue @ebuchman and welcome to the Go project!

I shall kindly page some runtime folks to take a look: /cc @RLH @aclements @randall77


Copy link

@davecheney davecheney commented Feb 17, 2019

@ebuchman sha256.New returns a value boxed inside a hash.Hash interface. The value allocated by sha256.New has escaped to the heap -- you can verify that with go build -gcflags=-m

Why did you expect this code to not allocate a value on the heap? Is it because you are not using the result from sha256.New?


Copy link

@FiloSottile FiloSottile commented Feb 18, 2019

The confusion might be due to the fact that the heap profile raw format includes all allocated values, live and collected. To see if it's still live after GC, use go tool pprof -inuse_objects.


Copy link

@rsc rsc commented Apr 23, 2019

There's no leak here. Run this in a loop and you will see that the heap is not growing. The "0: 0" in the raw format means there are none of them live now.


@rsc rsc closed this Apr 23, 2019
@golang golang locked and limited conversation to collaborators Apr 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants