Skip to content

Commit a696477

Browse files
committed
[ CID 14847 ] Fix incorrect deallocator issue
1 parent ef106ed commit a696477

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

engine/src/mode_standalone.cpp

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,14 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
322322

323323
case kMCCapsuleSectionTypeModule:
324324
{
325-
char *t_module_data;
326-
t_module_data = new char[p_length];
327-
if (IO_read(t_module_data, p_length, p_stream) != IO_NORMAL)
325+
MCAutoByteArray t_module_data;
326+
if (!t_module_data.New(p_length))
327+
{
328+
MCresult -> sets("out of memory");
329+
return false;
330+
}
331+
332+
if (IO_read(t_module_data.Bytes(), p_length, p_stream) != IO_NORMAL)
328333
{
329334
MCresult -> sets("failed to read module");
330335
return false;
@@ -336,15 +341,14 @@ bool MCStandaloneCapsuleCallback(void *p_self, const uint8_t *p_digest, MCCapsul
336341
MCStreamRef t_stream;
337342
t_stream = nil;
338343
if (t_success)
339-
t_success = MCMemoryInputStreamCreate(t_module_data, p_length, t_stream);
344+
t_success = MCMemoryInputStreamCreate(t_module_data.Bytes(), p_length, t_stream);
340345

341346
MCScriptModuleRef t_module;
342347
if (t_success)
343348
t_success = MCScriptCreateModuleFromStream(t_stream, t_module);
344349

345350
if (t_stream != nil)
346351
MCValueRelease(t_stream);
347-
free(t_module_data);
348352

349353
if (!t_success)
350354
{

0 commit comments

Comments
 (0)