{"action":"created","issue":{"url":"https://api.github.com/repos/google/re2/issues/28","labels_url":"https://api.github.com/repos/google/re2/issues/28/labels{/name}","comments_url":"https://api.github.com/repos/google/re2/issues/28/comments","events_url":"https://api.github.com/repos/google/re2/issues/28/events","html_url":"https://github.com/google/re2/issues/28","id":84485551,"number":28,"title":"Minor leaks at initialisation","user":{"login":"marmeladema","id":1629419,"avatar_url":"https://avatars.githubusercontent.com/u/1629419?v=3","gravatar_id":"","url":"https://api.github.com/users/marmeladema","html_url":"https://github.com/marmeladema","followers_url":"https://api.github.com/users/marmeladema/followers","following_url":"https://api.github.com/users/marmeladema/following{/other_user}","gists_url":"https://api.github.com/users/marmeladema/gists{/gist_id}","starred_url":"https://api.github.com/users/marmeladema/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/marmeladema/subscriptions","organizations_url":"https://api.github.com/users/marmeladema/orgs","repos_url":"https://api.github.com/users/marmeladema/repos","events_url":"https://api.github.com/users/marmeladema/events{/privacy}","received_events_url":"https://api.github.com/users/marmeladema/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2015-06-03T10:34:48Z","updated_at":"2015-06-04T11:36:44Z","closed_at":"2015-06-04T11:36:44Z","body":"Hi all,\r\n\r\nI've noticed some minor leaks because of RE2 initialisation mechanism :\r\n```\r\n// static empty things for use as const references.\r\n// To avoid global constructors, initialized on demand.\r\nGLOBAL_MUTEX(empty_mutex);\r\nstatic const string *empty_string;\r\nstatic const map<string, int> *empty_named_groups;\r\nstatic const map<int, string> *empty_group_names;\r\n\r\nstatic void InitEmpty() {\r\n  GLOBAL_MUTEX_LOCK(empty_mutex);\r\n  if (empty_string == NULL) {\r\n    empty_string = new string;\r\n    empty_named_groups = new map<string, int>;\r\n    empty_group_names = new map<int, string>;\r\n  }\r\n  GLOBAL_MUTEX_UNLOCK(empty_mutex);\r\n}\r\n```\r\nThose three allocated objects are never freed, or maybe i did not find a way to do it ...\r\nWouldn't it be better to have those three objects in the RE2 object ? So that it can be properly freed during destructor.\r\nI know that it would increase RE2 objects' size a little bit but imo it is worthwhile.\r\nIt would also remove the need for a global mutex here.\r\n\r\nI can provide a patch if needed :)"},"comment":{"url":"https://api.github.com/repos/google/re2/issues/comments/108852396","html_url":"https://github.com/google/re2/issues/28#issuecomment-108852396","issue_url":"https://api.github.com/repos/google/re2/issues/28","id":108852396,"user":{"login":"junyer","id":3593753,"avatar_url":"https://avatars.githubusercontent.com/u/3593753?v=3","gravatar_id":"","url":"https://api.github.com/users/junyer","html_url":"https://github.com/junyer","followers_url":"https://api.github.com/users/junyer/followers","following_url":"https://api.github.com/users/junyer/following{/other_user}","gists_url":"https://api.github.com/users/junyer/gists{/gist_id}","starred_url":"https://api.github.com/users/junyer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/junyer/subscriptions","organizations_url":"https://api.github.com/users/junyer/orgs","repos_url":"https://api.github.com/users/junyer/repos","events_url":"https://api.github.com/users/junyer/events{/privacy}","received_events_url":"https://api.github.com/users/junyer/received_events","type":"User","site_admin":false},"created_at":"2015-06-04T11:36:44Z","updated_at":"2015-06-04T11:36:44Z","body":"It's true that the objects exist until program termination, but it's also true that their addresses are known – and needed – until program termination, so they aren't leaked. I'll admit that their lazy initialisation is kind of clunky, but we can't just use `std::call_once()` because that would require C++11."}}