Skip to content
This repository was archived by the owner on Aug 31, 2021. It is now read-only.

Commit a9b1a7d

Browse files
committed
[[ Bug 21918 ]] Memory leak when manipulating four-char-codes on macOS
This patch fixes a leak in the macOS platform specific FourCharCodeFromString function. In order to convert a string into a FourCharCode integer, the string is temporarily converted to a CString. Previously, however, this temporary CString was not being deleted. The explicit conversion has been replaced by an AutoStringRefAsCString auto class which fixes the leak.
1 parent a5f3460 commit a9b1a7d

File tree

2 files changed

+7
-5
lines changed

2 files changed

+7
-5
lines changed

docs/notes/bugfix-21918.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Fix memory leak when using legacy macOS features relying on four-char-codes
2+

engine/src/dskmac.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,14 @@ inline FourCharCode FourCharCodeFromString(const char *p_string)
8787

8888
bool FourCharCodeFromString(MCStringRef p_string, uindex_t p_start, FourCharCode& r_four_char_code)
8989
{
90-
char *temp;
90+
MCAutoStringRefAsCString t_temp;
9191
uint32_t t_four_char_code;
92-
if (!MCStringConvertToCString(p_string, temp))
92+
if (!t_temp.Lock(p_string))
9393
return false;
9494

95-
memcpy(&t_four_char_code, temp + p_start, 4);
95+
memcpy(&t_four_char_code, *t_temp + p_start, 4);
9696
r_four_char_code = MCSwapInt32HostToNetwork(t_four_char_code);
97-
delete temp;
97+
9898
return true;
9999
}
100100

@@ -109,7 +109,7 @@ inline char *FourCharCodeToString(FourCharCode p_code)
109109

110110
bool FourCharCodeToStringRef(FourCharCode p_code, MCStringRef& r_string)
111111
{
112-
return MCStringCreateWithCString(FourCharCodeToString(p_code), r_string);
112+
return MCStringCreateWithCStringAndRelease(FourCharCodeToString(p_code), r_string);
113113
}
114114

115115
struct triplets

0 commit comments

Comments
 (0)