{"action":"closed","issue":{"url":"https://api.github.com/repos/m-a-d-n-e-s-s/madness/issues/138","labels_url":"https://api.github.com/repos/m-a-d-n-e-s-s/madness/issues/138/labels{/name}","comments_url":"https://api.github.com/repos/m-a-d-n-e-s-s/madness/issues/138/comments","events_url":"https://api.github.com/repos/m-a-d-n-e-s-s/madness/issues/138/events","html_url":"https://github.com/m-a-d-n-e-s-s/madness/issues/138","id":84630151,"number":138,"title":"Memory leak in DQueue::grow()?","user":{"login":"justusc","id":5115941,"avatar_url":"https://avatars.githubusercontent.com/u/5115941?v=3","gravatar_id":"","url":"https://api.github.com/users/justusc","html_url":"https://github.com/justusc","followers_url":"https://api.github.com/users/justusc/followers","following_url":"https://api.github.com/users/justusc/following{/other_user}","gists_url":"https://api.github.com/users/justusc/gists{/gist_id}","starred_url":"https://api.github.com/users/justusc/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/justusc/subscriptions","organizations_url":"https://api.github.com/users/justusc/orgs","repos_url":"https://api.github.com/users/justusc/repos","events_url":"https://api.github.com/users/justusc/events{/privacy}","received_events_url":"https://api.github.com/users/justusc/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-06-03T15:45:09Z","updated_at":"2015-06-03T20:21:47Z","closed_at":"2015-06-03T20:21:47Z","body":"I am 99% certain I found a memory leak in DQueue::grow(). Since this is in a performance critical section, I want to be sure that there is nothing strange going on here, like purposefully leaking the memory, etc. I do not see any calls to delete in the file, other than in the destructor.\r\n\r\nThe relevant code is given below (see the comment at the end).\r\n\r\n```c++\r\nvoid grow() {\r\n    // ASSUME WE ALREADY HAVE THE MUTEX WHEN IN HERE\r\n    ++(stats.ngrow);\r\n    if (sz != n) MADNESS_EXCEPTION(\"assertion failure in dqueue::grow\", static_cast<int>(sz));\r\n    size_t oldsz = sz;\r\n    if (sz < 32768)\r\n        sz = 65536;\r\n    else if (sz <= 1048576)\r\n        sz *= 2;\r\n    else\r\n        sz += 1048576;\r\n    volatile T* volatile nbuf = new T[sz];\r\n    int lo = sz/2 - oldsz/2;\r\n    for (int i=_front; i<int(oldsz); ++i,++lo) {\r\n        nbuf[lo] = buf[i];\r\n    }\r\n    if (_front > 0) {\r\n        for (int i=0; i<=_back; ++i,++lo) {\r\n            nbuf[lo] = buf[i];\r\n        }\r\n    }\r\n    _front = sz/2 - oldsz/2;\r\n    _back = _front + n - 1;\r\n    //<<<<<<<<<<<<<<<<<<<<<< there should be a \"delete [] buf;\" here\r\n    buf = nbuf;\r\n    //sanity_check();\r\n}\r\n```"}}