{"action":"created","issue":{"url":"https://api.github.com/repos/libgit2/git2go/issues/163","labels_url":"https://api.github.com/repos/libgit2/git2go/issues/163/labels{/name}","comments_url":"https://api.github.com/repos/libgit2/git2go/issues/163/comments","events_url":"https://api.github.com/repos/libgit2/git2go/issues/163/events","html_url":"https://github.com/libgit2/git2go/issues/163","id":53223505,"number":163,"title":"garbage collector found invalid heap pointer: Go 1.4","user":{"login":"HawaiianSpork","id":193324,"avatar_url":"https://avatars.githubusercontent.com/u/193324?v=3","gravatar_id":"","url":"https://api.github.com/users/HawaiianSpork","html_url":"https://github.com/HawaiianSpork","followers_url":"https://api.github.com/users/HawaiianSpork/followers","following_url":"https://api.github.com/users/HawaiianSpork/following{/other_user}","gists_url":"https://api.github.com/users/HawaiianSpork/gists{/gist_id}","starred_url":"https://api.github.com/users/HawaiianSpork/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/HawaiianSpork/subscriptions","organizations_url":"https://api.github.com/users/HawaiianSpork/orgs","repos_url":"https://api.github.com/users/HawaiianSpork/repos","events_url":"https://api.github.com/users/HawaiianSpork/events{/privacy}","received_events_url":"https://api.github.com/users/HawaiianSpork/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":11,"created_at":"2015-01-01T16:50:20Z","updated_at":"2015-04-10T09:35:10Z","closed_at":null,"body":"After upgrading from go1.3 to go1.4, I'd get a runtime crash most of the time.  It crashes for various reasons (nil tree walker callback, invalid heap pointer...). Here is a scaled down version of the code that demonstrates the problem (runtime crashes most of the time).  Run this code with an argument pointing at a git repository like git2go.\r\n\r\n```go\r\npackage main\r\n\r\nimport (\r\n\t\"fmt\"\r\n\t\"github.com/libgit2/git2go\"\r\n\t\"os\"\r\n\t\"strings\"\r\n)\r\n\r\ntype MyRepo struct {\r\n\t*git.Repository\r\n}\r\n\r\nfunc (repository *MyRepo) foo(path string, treeEntry *git.TreeEntry) int {\r\n\tif git.ObjectBlob != treeEntry.Type {\r\n\t\treturn 0 // continue\r\n\t}\r\n\r\n\tif !strings.HasSuffix(treeEntry.Name, \".go\") {\r\n\t\treturn 0 // continue\r\n\t}\r\n\r\n\tblob, err := repository.Repository.LookupBlob(treeEntry.Id)\r\n\tdefer blob.Free()\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\r\n\tif blob.Size() > 10000 {\r\n\t\treturn 0 // continue\r\n\t}\r\n\r\n\tcontents := blob.Contents()\r\n\tif contents == nil {\r\n\t\tpanic(\"nil contents\")\r\n\t}\r\n\tfmt.Printf(\"%q\", path, treeEntry.Name, string(contents))\r\n\tfmt.Println()\r\n\r\n\treturn 0 // continue\r\n}\r\n\r\nfunc main() {\r\n\tfilename := os.Args[1]\r\n\r\n\trepository, err := git.OpenRepository(filename)\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\tdefer repository.Free()\r\n\r\n\tmyRepo := MyRepo{repository}\r\n\r\n\trevWalk, err := repository.Walk()\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\tdefer revWalk.Free()\r\n\r\n\t// Start out at the head\r\n\terr = revWalk.PushHead()\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n\r\n\terr = revWalk.Iterate(func(commit *git.Commit) bool {\r\n\t\tdefer commit.Free()\r\n\r\n\t\ttree, err := commit.Tree()\r\n\t\tif err != nil {\r\n\t\t\tpanic(err)\r\n\t\t}\r\n\t\tdefer tree.Free()\r\n\r\n\t\terr = tree.Walk(myRepo.foo)\r\n\t\tif err != nil {\r\n\t\t\tpanic(err)\r\n\t\t}\r\n\r\n\t\treturn true\r\n\t})\r\n\r\n\tif err != nil {\r\n\t\tpanic(err)\r\n\t}\r\n}\r\n```\r\n\r\nSome errors that come from the above code:\r\n\r\n```\r\npanic: runtime error: invalid memory address or nil pointer dereference\r\n[signal 0xb code=0x1 addr=0x0 pc=0x40f4299]\r\n\r\ngoroutine 1 [running]:\r\ngithub.com/libgit2/git2go.CallbackGitTreeWalk(0x438a520, 0x51008e0, 0xc208071e40, 0x0)\r\n\t/Users/maleticm/.gvm/pkgsets/go1.4/jack/src/github.com/libgit2/git2go/tree.go:99 +0x79\r\ngithub.com/libgit2/git2go._Cfunc__go_git_treewalk(0x5100850, 0x0, 0xc208069e40, 0x0)\r\n\t/Users/maleticm/.gvm/pkgsets/go1.4/jack/src/github.com/libgit2/git2go/:402 +0x43\r\ngithub.com/libgit2/git2go.Tree.Walk(0x5100850, 0xc20802c018, 0x5100850, 0xc208069e80, 0x0, 0x0)\r\n```\r\n\r\n```\r\nruntime: garbage collector found invalid heap pointer *(0xc208069cd0+0x10)=0xc208083e40 span=0xc20807e000-0xc208083800-0xc208084000 state=0\r\nfatal error: invalid heap pointer\r\n\r\nruntime stack:\r\nruntime.throw(0x437df83)\r\n\t/Users/maleticm/.gvm/gos/go1.4/src/runtime/panic.go:491 +0xad fp=0x7fff5fbfea18 sp=0x7fff5fbfe9e8\r\nscanblock(0xc208069cd0, 0x20, 0x42c12e4)\r\n\t/Users/maleticm/.gvm/gos/go1.4/src/runtime/mgc0.c:378 +0x551 fp=0x7fff5fbfeb58 sp=0x7fff5fbfea18\r\nscanframe(0x7fff5fbfec60, 0x0, 0x1)\r\n\t/Users/maleticm/.gvm/gos/go1.4/src/runtime/mgc0.c:740 +0x1c2 fp=0x7fff5fbfebc8 sp=0x7fff5fbfeb58\r\n```\r\n\r\n```\r\nunexpected fault address 0xb01dfacedebac1e\r\nfatal error: fault\r\n[signal 0xb code=0x1 addr=0xb01dfacedebac1e pc=0x40f4299]\r\n\r\ngoroutine 1 [running, locked to thread]:\r\nruntime.gothrow(0x426ec90, 0x5)\r\n\t/Users/maleticm/.gvm/gos/go1.4/src/runtime/panic.go:503 +0x8e fp=0xc208069c40 sp=0xc208069c28\r\nruntime.sigpanic()\r\n\t/Users/maleticm/.gvm/gos/go1.4/src/runtime/sigpanic_unix.go:29 +0x261 fp=0xc208069c90 sp=0xc208069c40\r\ngithub.com/libgit2/git2go.CallbackGitTreeWalk(0x438a520, 0x5009680, 0xc208073e40, 0x0)\r\n```"},"comment":{"url":"https://api.github.com/repos/libgit2/git2go/issues/comments/91493837","html_url":"https://github.com/libgit2/git2go/issues/163#issuecomment-91493837","issue_url":"https://api.github.com/repos/libgit2/git2go/issues/163","id":91493837,"user":{"login":"kron4eg","id":30984,"avatar_url":"https://avatars.githubusercontent.com/u/30984?v=3","gravatar_id":"","url":"https://api.github.com/users/kron4eg","html_url":"https://github.com/kron4eg","followers_url":"https://api.github.com/users/kron4eg/followers","following_url":"https://api.github.com/users/kron4eg/following{/other_user}","gists_url":"https://api.github.com/users/kron4eg/gists{/gist_id}","starred_url":"https://api.github.com/users/kron4eg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kron4eg/subscriptions","organizations_url":"https://api.github.com/users/kron4eg/orgs","repos_url":"https://api.github.com/users/kron4eg/repos","events_url":"https://api.github.com/users/kron4eg/events{/privacy}","received_events_url":"https://api.github.com/users/kron4eg/received_events","type":"User","site_admin":false},"created_at":"2015-04-10T09:35:10Z","updated_at":"2015-04-10T09:35:10Z","body":"@carlosmn I can't say exactly (in other case I'd send PR with fix), but looks like int pointer returned from libgit2 itself at some point. And Go1.4 runtime see it and crash."}}