mirror of
https://github.com/obsproject/obs-studio.git
synced 2026-08-24 10:14:13 -05:00
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:
+18
-4
@@ -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",
|
||||
|
||||
Reference in New Issue
Block a user