mirror of
https://git.dev.opencascade.org/repos/occt.git
synced 2025-04-21 10:13:43 +03:00
0024834: Allocation of memory for exception message must not throw another exception
- Add QA draw command OCC24834 - Make functions allocate_message/deallocate_message use malloc/free instead of operator new/delete - Eliminate compilation error on Linux Test case for issue CR24834
This commit is contained in:
parent
86b03c9774
commit
a73267f24b
@ -2111,6 +2111,72 @@ static Standard_Integer OCC24755 (Draw_Interpretor& di, Standard_Integer n, cons
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct MyStubObject
|
||||||
|
{
|
||||||
|
MyStubObject() : ptr(0L) {}
|
||||||
|
MyStubObject(void* thePtr) : ptr(thePtr) {}
|
||||||
|
char overhead[40];
|
||||||
|
void* ptr;
|
||||||
|
};
|
||||||
|
|
||||||
|
//=======================================================================
|
||||||
|
//function : OCC24834
|
||||||
|
//purpose :
|
||||||
|
//=======================================================================
|
||||||
|
static Standard_Integer OCC24834 (Draw_Interpretor& di, Standard_Integer n, const char** a)
|
||||||
|
{
|
||||||
|
if (n != 1)
|
||||||
|
{
|
||||||
|
std::cout << "Usage : " << a[0] << "\n";
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
NCollection_List<MyStubObject> aList;
|
||||||
|
const Standard_Integer aSmallBlockSize = 40;
|
||||||
|
const Standard_Integer aLargeBlockSize = 1500000;
|
||||||
|
|
||||||
|
// quick populate memory with large blocks
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
aList.Append(MyStubObject(Standard::Allocate(aLargeBlockSize)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Standard_Failure)
|
||||||
|
{
|
||||||
|
di << "caught out of memory for large blocks: OK\n";
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
di << "skept out of memory for large blocks: Error\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// allocate small blocks
|
||||||
|
try
|
||||||
|
{
|
||||||
|
for (;;)
|
||||||
|
{
|
||||||
|
aList.Append(MyStubObject(Standard::Allocate(aSmallBlockSize)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Standard_Failure)
|
||||||
|
{
|
||||||
|
di << "caught out of memory for small blocks: OK\n";
|
||||||
|
}
|
||||||
|
catch (...)
|
||||||
|
{
|
||||||
|
di << "skept out of memory for small blocks: Error\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
// release all allocated blocks
|
||||||
|
for (NCollection_List<MyStubObject>::Iterator it(aList); it.More(); it.Next())
|
||||||
|
{
|
||||||
|
Standard::Free(it.Value().ptr);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void QABugs::Commands_19(Draw_Interpretor& theCommands) {
|
void QABugs::Commands_19(Draw_Interpretor& theCommands) {
|
||||||
const char *group = "QABugs";
|
const char *group = "QABugs";
|
||||||
|
|
||||||
@ -2151,5 +2217,6 @@ void QABugs::Commands_19(Draw_Interpretor& theCommands) {
|
|||||||
theCommands.Add ("OCC24667", "OCC24667 result Wire_spine Profile [Mode [Approx]], no args to get help", __FILE__, OCC24667, group);
|
theCommands.Add ("OCC24667", "OCC24667 result Wire_spine Profile [Mode [Approx]], no args to get help", __FILE__, OCC24667, group);
|
||||||
theCommands.Add ("OCC24565", "OCC24565 FileNameIGS FileNameSTOR", __FILE__, OCC24565, group);
|
theCommands.Add ("OCC24565", "OCC24565 FileNameIGS FileNameSTOR", __FILE__, OCC24565, group);
|
||||||
theCommands.Add ("OCC24755", "OCC24755", __FILE__, OCC24755, group);
|
theCommands.Add ("OCC24755", "OCC24755", __FILE__, OCC24755, group);
|
||||||
|
theCommands.Add ("OCC24834", "OCC24834", __FILE__, OCC24834, group);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -25,13 +25,14 @@ static Standard_CString allocate_message(const Standard_CString AString)
|
|||||||
Standard_CString aStr = 0;
|
Standard_CString aStr = 0;
|
||||||
if(AString) {
|
if(AString) {
|
||||||
const Standard_Size aLen = strlen(AString);
|
const Standard_Size aLen = strlen(AString);
|
||||||
aStr = new Standard_Character[aLen+sizeof(Standard_Integer)+1];
|
aStr = (Standard_CString) malloc(aLen+sizeof(Standard_Integer)+1);
|
||||||
|
if (aStr) {
|
||||||
Standard_PCharacter pStr=(Standard_PCharacter)aStr;
|
Standard_PCharacter pStr=(Standard_PCharacter)aStr;
|
||||||
strcpy(pStr+sizeof(Standard_Integer),AString);
|
strcpy(pStr+sizeof(Standard_Integer),AString);
|
||||||
*((Standard_Integer*)aStr) = 1;
|
*((Standard_Integer*)aStr) = 1;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return aStr;
|
return aStr;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static Standard_CString copy_message(Standard_CString aMessage)
|
static Standard_CString copy_message(Standard_CString aMessage)
|
||||||
@ -49,7 +50,7 @@ static void deallocate_message(Standard_CString aMessage)
|
|||||||
if(aMessage) {
|
if(aMessage) {
|
||||||
(*((Standard_Integer*)aMessage))--;
|
(*((Standard_Integer*)aMessage))--;
|
||||||
if(*((Standard_Integer*)aMessage)==0)
|
if(*((Standard_Integer*)aMessage)==0)
|
||||||
delete [](Standard_PCharacter)aMessage;
|
free((void*)aMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
11
tests/bugs/fclasses/bug24834
Executable file
11
tests/bugs/fclasses/bug24834
Executable file
@ -0,0 +1,11 @@
|
|||||||
|
puts "================"
|
||||||
|
puts "OCC24834"
|
||||||
|
puts "================"
|
||||||
|
puts ""
|
||||||
|
#######################################################################
|
||||||
|
# Allocation of memory for exception message must not throw another exception
|
||||||
|
#######################################################################
|
||||||
|
|
||||||
|
pload QAcommands
|
||||||
|
|
||||||
|
OCC24834
|
Loading…
x
Reference in New Issue
Block a user