[Widelands-public] [ widelands-Bugs-2546252 ] src/sound/sound_handler.cc Memory and resource leaks
Status: Beta
Brought to you by:
sirver
From: SourceForge.net <no...@so...> - 2009-01-29 18:41:22
|
Bugs item #2546252, was opened at 2009-01-29 20:41 Message generated for change (Tracker Item Submitted) made by Item Submitter You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=427221&aid=2546252&group_id=40163 Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: None Group: None Status: Open Resolution: None Priority: 5 Private: No Submitted By: Reijo Tomperi (aggro80) Assigned to: Nobody/Anonymous (nobody) Summary: src/sound/sound_handler.cc Memory and resource leaks Initial Comment: In file src/sound/sound_handler.cc:276 Variable tempfile leaks memory in case #ifdef __WIN32__ is not true. (memory allocated with strdup) if (f == NULL) { log("Could not open %s for writing! Cannot load music.", tempfile); return NULL; } And actually this line can also leak memory: tempfile = mktemp(strdup("/tmp/widelands-sfx.XXXXXXXX")); As mktemp() will return NULL on failure. One should perhaps do this: tempfile = strdup("/tmp/widelands-sfx.XXXXXXXX"); if( !tempfile || mktemp( tempfile ) == NULL ) { log("Could not create tempfile /tmp/widelands-sfx.XXXXXXXX! Cannot load music."); free( tempfile ); return; } Note that this can be written inside the #else - #endif and the current check for if (tempfile == NULL) { can be removed, as the other route uses static memory and makes it impossible for tempfile to be NULL. In addition to this, tempfile and/or file (f) are not released in pretty much any unexpected end of function, so they can leak pretty much everywhere. All exists in that function should be checked to make sure leaks don't happen. Also pay attention to the #if #else structure to avoid crashes by trying to free static memory. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=427221&aid=2546252&group_id=40163 |