Skip to content

Commit e08c3dc

Browse files
committed
[[ Bug 21926 ]] Fix memory leak when using message box put command
This patch fixes a memory leak which occurs when using the message box targetting put command variant (i.e. put or put into msg). The leak was occurring due to a failure to delete the handler name and line number arguments (in the form of MCParmaeter instances). To fix this, the MCParameter instances are now allocated on the stack rather than on the heap.
1 parent 009e465 commit e08c3dc

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

docs/notes/bugfix-21926.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
# Fix memory leak when using put commands which target the message box

engine/src/debug.cpp

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,15 @@ void MCB_setmsg(MCExecContext &ctxt, MCStringRef p_string)
145145

146146
MCAutoStringRef t_handler;
147147
t_handler = MCNameGetString(ctxt.GetHandler()->getname());
148-
MCParameter *t_handler_parameter = new (nothrow) MCParameter;
149-
t_handler_parameter -> setvalueref_argument(*t_handler);
148+
MCParameter t_handler_parameter;
149+
t_handler_parameter.setvalueref_argument(*t_handler);
150150

151151
MCAutoNumberRef t_line;
152-
MCParameter *t_line_parameter;
152+
MCParameter t_line_parameter;
153153
if (MCNumberCreateWithUnsignedInteger(ctxt.GetLine(), &t_line))
154154
{
155-
t_line_parameter = new (nothrow) MCParameter;
156-
t_line_parameter -> setvalueref_argument(*t_line);
157-
t_handler_parameter -> setnext(t_line_parameter);
155+
t_line_parameter.setvalueref_argument(*t_line);
156+
t_handler_parameter.setnext(&t_line_parameter);
158157
}
159158

160159
bool t_added = false;
@@ -164,7 +163,7 @@ void MCB_setmsg(MCExecContext &ctxt, MCStringRef p_string)
164163
t_added = true;
165164
}
166165

167-
t_stat = t_target -> message(MCM_msgchanged, t_handler_parameter, True, True, False);
166+
t_stat = t_target -> message(MCM_msgchanged, &t_handler_parameter, True, True, False);
168167

169168
if (t_added)
170169
MCnexecutioncontexts--;

0 commit comments

Comments
 (0)