Skip to content

Commit 97988a1

Browse files
sofarnerzhul
authored andcommittedApr 17, 2017
Plug two minor Leaks (#5603)
* Resource leak: CHECK_FILE_ERR returns, without freeing chunk_name. Found with static analysis. * Resource leak: leaks `page` on error path. Found with static analysis.
1 parent 73de17a commit 97988a1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎src/cguittfont/CGUITTFont.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -512,9 +512,11 @@ CGUITTGlyphPage* CGUITTFont::createGlyphPage(const u8& pixel_mode)
512512
if (page_texture_size.Width > max_texture_size.Width || page_texture_size.Height > max_texture_size.Height)
513513
page_texture_size = max_texture_size;
514514

515-
if (!page->createPageTexture(pixel_mode, page_texture_size))
515+
if (!page->createPageTexture(pixel_mode, page_texture_size)) {
516516
// TODO: add error message?
517+
delete page;
517518
return 0;
519+
}
518520

519521
if (page)
520522
{

‎src/script/cpp_api/s_security.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,14 @@ bool ScriptApiSecurity::safeLoadFile(lua_State *L, const char *path)
406406

407407
// Read the file
408408
int ret = std::fseek(fp, 0, SEEK_END);
409-
CHECK_FILE_ERR(ret, fp);
409+
if (ret) {
410+
lua_pushfstring(L, "%s: %s", path, strerror(errno));
411+
std::fclose(fp);
412+
if (path) {
413+
delete [] chunk_name;
414+
}
415+
return false;
416+
}
410417

411418
size_t size = std::ftell(fp) - start;
412419
char *code = new char[size];

0 commit comments

Comments
 (0)
Please sign in to comment.