libobs: Log errors for bmalloc(0)

malloc(0) is implementation defined and almost always a mistake. I
believe we should be more like malloc and treat bmalloc(0) as an error
instead of tying to handle it. For now we can log an error in case 3rd
party plugins are broken, in the future I would suggest this becomes a
crash-worthy error.
This commit is contained in:
Richard Stanway
2022-07-16 15:20:55 -07:00
committed by Jim
parent dbdbfe79d2
commit c5965c8605
+18 -4
View File
@@ -91,9 +91,16 @@ static long num_allocs = 0;
void *bmalloc(size_t size)
{
if (!size) {
blog(LOG_ERROR,
"bmalloc: Allocating 0 bytes is broken behavior, please "
"fix your code! This will crash in future versions of "
"OBS.");
size = 1;
}
void *ptr = a_malloc(size);
if (!ptr && !size)
ptr = a_malloc(1);
if (!ptr) {
os_breakpoint();
bcrash("Out of memory while trying to allocate %lu bytes",
@@ -109,9 +116,16 @@ void *brealloc(void *ptr, size_t size)
if (!ptr)
os_atomic_inc_long(&num_allocs);
if (!size) {
blog(LOG_ERROR,
"brealloc: Allocating 0 bytes is broken behavior, please "
"fix your code! This will crash in future versions of "
"OBS.");
size = 1;
}
ptr = a_realloc(ptr, size);
if (!ptr && !size)
ptr = a_realloc(ptr, 1);
if (!ptr) {
os_breakpoint();
bcrash("Out of memory while trying to allocate %lu bytes",