Skip to content

GetRegistryLanguage contains a static ascii string that can leak memory and throws a reference count assert. #913

Open
@Mauller

Description

@Mauller

Registry.cpp contains a staticly defined Asciistring that appears to have memory issues, there is also a comment stating that static with ascii strings causes a memory leak.

 	generalszh.exe!doCrashBox(const char * buffer, bool logResult) Line 293	C++
 	generalszh.exe!DebugCrash(const char * format, ...) Line 517	C++
 	generalszh.exe!AsciiString::validate() Line 101	C++
 	generalszh.exe!AsciiString::AsciiString(const AsciiString & stringSrc) Line 93	C++
>	generalszh.exe!GetRegistryLanguage() Line 171	C++
 	generalszh.exe!AudioEventRTS::generateFilenamePrefix(AudioType audioTypeToPlay, bool localized) Line 785	C++
 	generalszh.exe!AudioEventRTS::adjustForLocalization(AsciiString & strToAdjust) Line 814	C++
 	generalszh.exe!AudioEventRTS::generatePlayInfo() Line 402	C++
 	generalszh.exe!AudioManager::addAudioEvent(const AudioEventRTS * eventToAdd) Line 459	C++
 	generalszh.exe!MilesAudioManager::addAudioEvent(const AudioEventRTS * eventToAdd) Line 127	C++
 	generalszh.exe!Drawable::startAmbientSound(BodyDamageType dt, TimeOfDay tod, bool onlyIfPermanent) Line 4535	C++
 	generalszh.exe!Drawable::startAmbientSound(bool onlyIfPermanent) Line 4565	C++
 	generalszh.exe!Drawable::updateDrawable() Line 1337	C++
 	generalszh.exe!GameClient::update() Line 727	C++
 	generalszh.exe!W3DGameClient::update() Line 94	C++
 	generalszh.exe!SubsystemInterface::UPDATE() Line 78	C++
 	generalszh.exe!GameEngine::update() Line 741	C++
 	generalszh.exe!Win32GameEngine::update() Line 90	C++
 	generalszh.exe!GameEngine::execute() Line 815	C++
 	generalszh.exe!GameMain(int argc, char * * argv) Line 44	C++
 	generalszh.exe!WinMain(HINSTANCE__ * hInstance, HINSTANCE__ * hPrevInstance, char * lpCmdLine, int nCmdShow) Line 1040	C++

This was the callstack when it threw.

AsciiString GetRegistryLanguage(void)
{
	static Bool cached = FALSE;
	// NOTE: static causes a memory leak, but we have to keep it because the value is cached.
	static AsciiString val = "english";
	if (cached) {
		return val;
	} else {
		cached = TRUE;
	}

	GetStringFromRegistry("", "Language", val);
	return val;
}

And the offending code above.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugSomething is not working right, typically is user facingGenRelates to GeneralsMemoryIs memory relatedZHRelates to Zero Hour

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions