Skip to content

Commit a5b2428

Browse files
authored
Fix crash in monitored .NET process when an exception does not have an exception message (#201)
1 parent dfa094b commit a5b2428

1 file changed

Lines changed: 16 additions & 10 deletions

File tree

profiler/src/ProcDumpProfiler.cpp

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,7 +1225,7 @@ String CorProfiler::GetExceptionMessage(ObjectID objectId)
12251225
}
12261226

12271227
//
1228-
// Loop to lcoate the "_message" field
1228+
// Loop to locate the "_message" field
12291229
// Get stringLength from the "_message" field stringLengthOffset
12301230
// Copy the number of (stringLength+1) WCHARs from the "_message" field stringBufferOffset to our stringBuffer
12311231
//
@@ -1251,18 +1251,24 @@ String CorProfiler::GetExceptionMessage(ObjectID objectId)
12511251
delete [] pFieldOffsets;
12521252
return WCHAR("");
12531253
}
1254+
12541255
msgField = *(PLONG_PTR)(((BYTE *)objectId) + pFieldOffsets[fieldIndex].ulOffset);
1255-
stringLength = *(PINT32)((BYTE *)msgField + stringLengthOffset);
1256-
stringBuffer = new WCHAR[stringLength+1];
1257-
if(stringBuffer==NULL)
1256+
if(msgField != NULL)
12581257
{
1259-
LOG(TRACE) << "CorProfiler::GetExceptionMessage: Failed memory allocation for stringBuffer";
1260-
if(metadata != NULL) metadata->Release();
1261-
delete [] pFieldOffsets;
1262-
return WCHAR("");;
1258+
stringLength = *(PINT32)((BYTE *)msgField + stringLengthOffset);
1259+
stringBuffer = new WCHAR[stringLength+1];
1260+
if(stringBuffer==NULL)
1261+
{
1262+
LOG(TRACE) << "CorProfiler::GetExceptionMessage: Failed memory allocation for stringBuffer";
1263+
if(metadata != NULL) metadata->Release();
1264+
delete [] pFieldOffsets;
1265+
return WCHAR("");;
1266+
}
1267+
1268+
memcpy(stringBuffer, (BYTE *)msgField+stringBufferOffset,(stringLength+1)*sizeof(WCHAR));
1269+
msg+=stringBuffer;
12631270
}
1264-
memcpy(stringBuffer, (BYTE *)msgField+stringBufferOffset,(stringLength+1)*sizeof(WCHAR));
1265-
msg+=stringBuffer;
1271+
12661272
break;
12671273
}
12681274
}

0 commit comments

Comments
 (0)