mirror of https://github.com/ZDoom/qzdoom.git
- the timidity safe_malloc functions may not throw exceptions.
There is a high chance of them getting called within the stream servicing function which cannot deal with abnormal conditions, so the only choice here is performing a hard abort.
This commit is contained in:
parent
fe0a6b00ce
commit
c24f9b42ba
|
@ -34,6 +34,7 @@ namespace Timidity
|
||||||
/* This'll allocate memory or die. */
|
/* This'll allocate memory or die. */
|
||||||
void *safe_malloc(size_t count)
|
void *safe_malloc(size_t count)
|
||||||
{
|
{
|
||||||
|
#if 0
|
||||||
char buffer[80];
|
char buffer[80];
|
||||||
void *p;
|
void *p;
|
||||||
if (count > (1 << 21))
|
if (count > (1 << 21))
|
||||||
|
@ -51,6 +52,15 @@ void *safe_malloc(size_t count)
|
||||||
throw std::runtime_error(buffer);
|
throw std::runtime_error(buffer);
|
||||||
}
|
}
|
||||||
return 0; // Unreachable.
|
return 0; // Unreachable.
|
||||||
|
#else
|
||||||
|
// No, we cannot throw exceptions here - this code can get called from real-time worker threads.
|
||||||
|
auto p = malloc(count);
|
||||||
|
if (!p)
|
||||||
|
{
|
||||||
|
std::terminate(); // we must abort, though...
|
||||||
|
}
|
||||||
|
return p;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -39,7 +39,7 @@ void *safe_malloc(size_t count)
|
||||||
auto p = malloc(count);
|
auto p = malloc(count);
|
||||||
if (p == nullptr)
|
if (p == nullptr)
|
||||||
{
|
{
|
||||||
// I_FatalError("Out of memory");
|
abort();
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -54,7 +54,7 @@ void *safe_realloc(void *ptr, size_t count)
|
||||||
auto p = realloc(ptr, count);
|
auto p = realloc(ptr, count);
|
||||||
if (p == nullptr)
|
if (p == nullptr)
|
||||||
{
|
{
|
||||||
// I_FatalError("Out of memory");
|
abort();
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
@ -65,7 +65,7 @@ char *safe_strdup(const char *s)
|
||||||
auto p = strdup(s);
|
auto p = strdup(s);
|
||||||
if (p == nullptr)
|
if (p == nullptr)
|
||||||
{
|
{
|
||||||
// I_FatalError("Out of memory");
|
abort();
|
||||||
}
|
}
|
||||||
return p;
|
return p;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue