TITANIC: Fix memory leak

TTsynonym constructor copies the value of the incoming string, it does
not take ownership.

Coverity CID 1361031
This commit is contained in:
sluicebox 2023-11-02 09:26:17 -07:00
parent fa6454ef4f
commit 23901f22ee
3 changed files with 4 additions and 5 deletions

View File

@ -39,8 +39,8 @@ TTsynonym::TTsynonym(int mode, const char *str, FileHandle file) :
_file = file;
}
TTsynonym::TTsynonym(int mode, TTstring *str) : TTstringNode() {
_string = *str;
TTsynonym::TTsynonym(int mode, const TTstring &str) : TTstringNode() {
_string = str;
initialize(mode);
}

View File

@ -32,7 +32,7 @@ public:
TTsynonym();
TTsynonym(const TTsynonym *src);
TTsynonym(int mode, const char *str, FileHandle file);
TTsynonym(int mode, TTstring *str);
TTsynonym(int mode, const TTstring &str);
/**
* Copies data from one synonym to another

View File

@ -120,8 +120,7 @@ int TTword::setSynStr(TTstring &str) {
if (str.empty())
return 4;
TTstring *newStr = new TTstring(str);
TTsynonym *newSyn = new TTsynonym(4, newStr);
TTsynonym *newSyn = new TTsynonym(4, str);
setSyn(newSyn);
return 0;
}