{"action":"created","issue":{"url":"https://api.github.com/repos/collectd/go-collectd/issues/26","repository_url":"https://api.github.com/repos/collectd/go-collectd","labels_url":"https://api.github.com/repos/collectd/go-collectd/issues/26/labels{/name}","comments_url":"https://api.github.com/repos/collectd/go-collectd/issues/26/comments","events_url":"https://api.github.com/repos/collectd/go-collectd/issues/26/events","html_url":"https://github.com/collectd/go-collectd/issues/26","id":177751688,"number":26,"title":"malloc() issue with more  than 3 values","user":{"login":"vbatoufflet","id":598433,"avatar_url":"https://avatars0.githubusercontent.com/u/598433?v=4","gravatar_id":"","url":"https://api.github.com/users/vbatoufflet","html_url":"https://github.com/vbatoufflet","followers_url":"https://api.github.com/users/vbatoufflet/followers","following_url":"https://api.github.com/users/vbatoufflet/following{/other_user}","gists_url":"https://api.github.com/users/vbatoufflet/gists{/gist_id}","starred_url":"https://api.github.com/users/vbatoufflet/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/vbatoufflet/subscriptions","organizations_url":"https://api.github.com/users/vbatoufflet/orgs","repos_url":"https://api.github.com/users/vbatoufflet/repos","events_url":"https://api.github.com/users/vbatoufflet/events{/privacy}","received_events_url":"https://api.github.com/users/vbatoufflet/received_events","type":"User","site_admin":false},"labels":[{"id":183750466,"url":"https://api.github.com/repos/collectd/go-collectd/labels/bug","name":"bug","color":"fc2929","default":true},{"id":183750469,"url":"https://api.github.com/repos/collectd/go-collectd/labels/help%20wanted","name":"help wanted","color":"159818","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-09-19T10:34:27Z","updated_at":"2017-12-20T19:59:51Z","closed_at":null,"author_association":"NONE","body":"Hi @octo,\n\nI ran into a strange error when trying to implement a plugin using `collect.org/api/plugin`.\n\nWhen I send more than 3 values in `[]api.Value{}`, I get `malloc()` errors in Collectd.\n\nFor example:\n\n```\npackage main\n\nimport (\n    \"time\"\n\n    \"collectd.org/api\"\n    \"collectd.org/plugin\"\n)\n\ntype Realloc3 struct{}\n\nfunc (Realloc3) Read() error {\n    if err := plugin.Write(&api.ValueList{\n        Identifier: api.Identifier{\n            Host:         \"example\",\n            Plugin:       \"realloc3\",\n            Type:         \"realloc3\",\n            TypeInstance: \"demo\",\n        },\n        Time:     time.Now(),\n        Interval: 10 * time.Second,\n        DSNames:  []string{\"a\", \"b\", \"c\"},\n        Values:   []api.Value{api.Derive(1), api.Derive(2), api.Derive(3)},\n    }); err != nil {\n        plugin.Error(err)\n    }\n\n    return nil\n}\n\nfunc init() {\n    plugin.RegisterRead(\"realloc3\", &Realloc3{})\n}\n\nfunc main() {}\n```\n\ngives me:\n\n```\n# CGO_CPPFLAGS='-I/usr/include/collectd/core/daemon -I/usr/include/collectd/core' go build -buildmode=c-shared -o realloc3.so realloc3.go\n\n# collectd -f\nInitialization complete, entering read-loop.\ntcpconns plugin: Reading from netlink succeeded. Will use the netlink method from now on.\n^CExiting normally.\ncollectd: Stopping 5 read threads.\ncollectd: Stopping 5 write threads.\n```\n\nbut with (which basically adds a fourth value):\n\n```\npackage main\n\nimport (\n    \"time\"\n\n    \"collectd.org/api\"\n    \"collectd.org/plugin\"\n)\n\ntype Realloc4 struct{}\n\nfunc (Realloc4) Read() error {\n    if err := plugin.Write(&api.ValueList{\n        Identifier: api.Identifier{\n            Host:         \"example\",\n            Plugin:       \"realloc4\",\n            Type:         \"realloc4\",\n            TypeInstance: \"demo\",\n        },\n        Time:     time.Now(),\n        Interval: 10 * time.Second,\n        DSNames:  []string{\"a\", \"b\", \"c\", \"d\"},\n        Values:   []api.Value{api.Derive(1), api.Derive(2), api.Derive(3), api.Derive(4)},\n    }); err != nil {\n        plugin.Error(err)\n    }\n\n    return nil\n}\n\nfunc init() {\n    plugin.RegisterRead(\"realloc4\", &Realloc4{})\n}\n\nfunc main() {}\n```\n\nI get:\n\n```\n# CGO_CPPFLAGS='-I/usr/include/collectd/core/daemon -I/usr/include/collectd/core' go build -buildmode=c-shared -o realloc4.so realloc4.go\n\n# collectd -f\nInitialization complete, entering read-loop.\ncollectd: malloc.c:2372: sysmalloc: Assertion `(old_top == (((mbinptr) (((char *) &((av)->bins[((1) - 1) * 2])) - __builtin_offsetof (struct malloc_chunk, fd)))) && old_size == 0) || ((unsigned long) (old_size) >= (unsigned long)((((__builtin_offsetof (struct malloc_chunk, fd_nextsize))+((2 *(sizeof(size_t))) - 1)) & ~((2 *(sizeof(size_t))) - 1))) && ((old_top)->size & 0x1) && ((unsigned long) old_end & pagemask) == 0)' failed.\nAborted\n\n# collectd -f\nInitialization complete, entering read-loop.\n*** Error in `collectd': malloc(): memory corruption: 0x00007fca08000900 ***\ntcpconns plugin: Reading from netlink succeeded. Will use the netlink method from now on.\nAborted\n```\n\nDid I miss something important or did I do something wrong?\n\nKind regards,\nVincent\n"},"comment":{"url":"https://api.github.com/repos/collectd/go-collectd/issues/comments/353167369","html_url":"https://github.com/collectd/go-collectd/issues/26#issuecomment-353167369","issue_url":"https://api.github.com/repos/collectd/go-collectd/issues/26","id":353167369,"user":{"login":"iMilnb","id":1702247,"avatar_url":"https://avatars0.githubusercontent.com/u/1702247?v=4","gravatar_id":"","url":"https://api.github.com/users/iMilnb","html_url":"https://github.com/iMilnb","followers_url":"https://api.github.com/users/iMilnb/followers","following_url":"https://api.github.com/users/iMilnb/following{/other_user}","gists_url":"https://api.github.com/users/iMilnb/gists{/gist_id}","starred_url":"https://api.github.com/users/iMilnb/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/iMilnb/subscriptions","organizations_url":"https://api.github.com/users/iMilnb/orgs","repos_url":"https://api.github.com/users/iMilnb/repos","events_url":"https://api.github.com/users/iMilnb/events{/privacy}","received_events_url":"https://api.github.com/users/iMilnb/received_events","type":"User","site_admin":false},"created_at":"2017-12-20T19:59:51Z","updated_at":"2017-12-20T19:59:51Z","author_association":"NONE","body":"FWIW I've been hit by the same bug, 3 DSNames and Values, all clear. 4 DSNames and Values, segfault."}}
{"actor":{"display_login":"iMilnb"}}