{"action":"created","issue":{"url":"https://api.github.com/repos/BOINC/boinc/issues/1356","labels_url":"https://api.github.com/repos/BOINC/boinc/issues/1356/labels{/name}","comments_url":"https://api.github.com/repos/BOINC/boinc/issues/1356/comments","events_url":"https://api.github.com/repos/BOINC/boinc/issues/1356/events","html_url":"https://github.com/BOINC/boinc/pull/1356","id":59761489,"number":1356,"title":"BoincAPI Windows static CRT leak","user":{"login":"JasonGroothuis","id":11306956,"avatar_url":"https://avatars.githubusercontent.com/u/11306956?v=3","gravatar_id":"","url":"https://api.github.com/users/JasonGroothuis","html_url":"https://github.com/JasonGroothuis","followers_url":"https://api.github.com/users/JasonGroothuis/followers","following_url":"https://api.github.com/users/JasonGroothuis/following{/other_user}","gists_url":"https://api.github.com/users/JasonGroothuis/gists{/gist_id}","starred_url":"https://api.github.com/users/JasonGroothuis/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JasonGroothuis/subscriptions","organizations_url":"https://api.github.com/users/JasonGroothuis/orgs","repos_url":"https://api.github.com/users/JasonGroothuis/repos","events_url":"https://api.github.com/users/JasonGroothuis/events{/privacy}","received_events_url":"https://api.github.com/users/JasonGroothuis/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":7,"created_at":"2015-03-04T07:46:43Z","updated_at":"2015-03-05T06:13:56Z","closed_at":null,"pull_request":{"url":"https://api.github.com/repos/BOINC/boinc/pulls/1356","html_url":"https://github.com/BOINC/boinc/pull/1356","diff_url":"https://github.com/BOINC/boinc/pull/1356.diff","patch_url":"https://github.com/BOINC/boinc/pull/1356.patch"},"body":"Handle and resource leakage corrected for main application timer thread\r\n(first cut).  This covers the ordinary boinc_finish() run to completion\r\nsituation only. Medium speed XP 32 bit host estimated at 2-6 weeks\r\nbetween needing a reboot due to low kernel resources.  One actual host\r\nunder observation exhibited the 'reboot to clear'  issue after 7 weeks,\r\n\r\nThe API will need further attention to what happens to the timer thread\r\nhandle and resources under various unusual exit conditions, perhaps\r\nmoving cleanup  to boinc_exit(), however since the timer thread calls\r\nboinc_exit(), that's problematic. Cases of client shutdown, abort and\r\nerror exits, will need investigation, along with API review for the\r\ndynamic C Runtime  with respect to handles.;  A Test Protocol should be\r\ndevised once applicable other areas are identified.\r\n\r\nSee MSDN documentation for _beignthreadex() and CreateThread() for\r\nVisual Studio 2008/2010/2013, for details."},"comment":{"url":"https://api.github.com/repos/BOINC/boinc/issues/comments/77312624","html_url":"https://github.com/BOINC/boinc/pull/1356#issuecomment-77312624","issue_url":"https://api.github.com/repos/BOINC/boinc/issues/1356","id":77312624,"user":{"login":"romw","id":985772,"avatar_url":"https://avatars.githubusercontent.com/u/985772?v=3","gravatar_id":"","url":"https://api.github.com/users/romw","html_url":"https://github.com/romw","followers_url":"https://api.github.com/users/romw/followers","following_url":"https://api.github.com/users/romw/following{/other_user}","gists_url":"https://api.github.com/users/romw/gists{/gist_id}","starred_url":"https://api.github.com/users/romw/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/romw/subscriptions","organizations_url":"https://api.github.com/users/romw/orgs","repos_url":"https://api.github.com/users/romw/repos","events_url":"https://api.github.com/users/romw/events{/privacy}","received_events_url":"https://api.github.com/users/romw/received_events","type":"User","site_admin":false},"created_at":"2015-03-05T06:13:55Z","updated_at":"2015-03-05T06:13:55Z","body":"> In practice (most noticeable on the XP scenario) it boils down to that the C Runtime is multithreaded,\r\n> so allocates additional resources inside, that Windows API function won;t know about, This (small)\r\n> cumulative leak is what manifests most in the 2Gib kernel space under XP.. \r\n\r\nBoth _beginthreadex() and _endthreadex() end up calling CreateThread() and ExitThread() respectively.\r\n\r\nAs near as I can tell the memory leak that the first article is concerned about occurs if you call _beginthreadex() and terminate the thread with TerminateThread().  _beginthread()/_beginthreadex() makes a call to _calloc_crt to store internal information used by the CRT functions that require thread/process handles and the like. See: <VSInstallDir>/VC/crt/src/threadex.c\r\n\r\nNone of that is stored in the kernel address space.\r\n\r\nAs far as TerminateProcess() is concerned, it is more or less required until such time as the BOINC API becomes a little more symmetrical as far as the API contracts are concerned.  Science applications can create one or more threads for their use that the BOINC API doesn't know about.\r\n"}}