Khronos Public Bugzilla
Bug 572 - Memory leak after using _ktxUnpackETC (also no result status check)
Memory leak after using _ktxUnpackETC (also no result status check)
Status: RESOLVED FIXED
Product: KTX
Classification: Unclassified
Component: library
unspecified
All All
: P3 major
: ---
Assigned To: Mark Callow
:
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-01-10 10:03 PST by Krystian Bigaj
Modified: 2012-01-17 19:18 PST (History)
0 users

See Also:


Attachments
Patch for loader.c to fix memory leak (and check result code) (745 bytes, patch)
2012-01-10 10:03 PST, Krystian Bigaj
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Krystian Bigaj 2012-01-10 10:03:35 PST
Created attachment 91 [details]
Patch for loader.c to fix memory leak (and check result code)

After successful _ktxUnpackETC call (in loader.c), memory allocated for 'unpacked' variable (inside function) is not released after using, so leaking memory - in my case total leak is about 0,5MB per mip-mapped texture:

_ktxUnpackETC(data, &unpacked, pixelWidth, pixelHeight);
glTexImage2D(texinfo.glTarget + face, level, 
	GL_RGB, pixelWidth, pixelHeight, 0, 
	GL_RGB, GL_UNSIGNED_BYTE, unpacked);

Also there is no result code check.
Suggested fix (also as a patch in attachment):

errorCode = _ktxUnpackETC(data, &unpacked, pixelWidth, pixelHeight);
if (errorCode != KTX_SUCCESS) {
	goto cleanup;
}
glTexImage2D(texinfo.glTarget + face, level, 
	GL_RGB, pixelWidth, pixelHeight, 0, 
	GL_RGB, GL_UNSIGNED_BYTE, unpacked);
free(unpacked);
Comment 1 Mark Callow 2012-01-17 19:18:38 PST
In SVN r16605.