{"action":"opened","issue":{"url":"https://api.github.com/repos/nothings/stb/issues/75","labels_url":"https://api.github.com/repos/nothings/stb/issues/75/labels{/name}","comments_url":"https://api.github.com/repos/nothings/stb/issues/75/comments","events_url":"https://api.github.com/repos/nothings/stb/issues/75/events","html_url":"https://github.com/nothings/stb/issues/75","id":55014334,"number":75,"title":"Several memory leaks in \"stb_vorbis.c\"","user":{"login":"BigJim","id":424358,"avatar_url":"https://avatars.githubusercontent.com/u/424358?v=3","gravatar_id":"","url":"https://api.github.com/users/BigJim","html_url":"https://github.com/BigJim","followers_url":"https://api.github.com/users/BigJim/followers","following_url":"https://api.github.com/users/BigJim/following{/other_user}","gists_url":"https://api.github.com/users/BigJim/gists{/gist_id}","starred_url":"https://api.github.com/users/BigJim/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/BigJim/subscriptions","organizations_url":"https://api.github.com/users/BigJim/orgs","repos_url":"https://api.github.com/users/BigJim/repos","events_url":"https://api.github.com/users/BigJim/events{/privacy}","received_events_url":"https://api.github.com/users/BigJim/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2015-01-21T12:50:57Z","updated_at":"2015-01-21T12:50:57Z","closed_at":null,"body":"First of all thanks for this great module and your other fine works.\r\n\r\nMy configuration: MS VS2013 w/STB_VORBIS_NO_STDIO & STB_VORBIS_NO_PUSHDATA_API\r\ndefined as I load my Oggs from a resource w/no streaming.\r\n\r\nAs I usually like to do with such algorithmic setups I tweaked stb_vorbis to use it's own private local heap with a HeapCreate() then I put macros to replace all malloc, realloc, and free() calls with HeapAlloc, HeapReAlloc, and HeapFree's respectively;\r\nAdded two methods, a \"stb_vorbis_free_buffer(short *buffer);\" to free up the buffer returned by \"stb_vorbis_decode_memory\", then after the Ogg has played a \"stb_vorbis_heap_destroy()\" calls \"HeapDestroy\" to remove this private heap.\r\n\r\nJust to check, I run a two second Ogg and setup a mini-memory test setup looping HeapWalk() to count any unfreed blocks and sum up the bytes.\r\nTo my surprise my trace text: \"Total 1094016 bytes leak from 101 unfreed blocks.\" The total is ∑(cbData + cbOverhead).\r\n\r\nNow not really a problem for me since I destroy this heap after each play it mitigates any leaks, but not good if you are still using the default/main heap (loosing ~1mb each play).\r\n\r\nI expanded my \"poorman's\" memory tracker by putting stubs around the HeapAlloc and HeapReAlloc to trace out the pointers, sizes, and source line #'s. Tried to trace it down for a few hours but the control flow in the inner decoding loops are not trivial.  \r\nI see a few large blocks leaked and then a bunch of 128byte sized, then a large one (126992), then a string of 8 sized blocks..\r\nCould be it's allocating a something twice, or just not freeing them in the end (almost the same but different). \r\n\r\nIf you want I'll send you a text paste of the setup I'm using, and, or recommend you use some sort of memory tracer package.\r\n\r\nThanks,"}}