I decided to test this out on my own computer using this code:
Code:
#include <stdio.h>
#include <stdlib.h>
#define MB (1024 * 1024)
int main(int argc, char *argv[])
{
char *mem = NULL;
long long unsigned int size = MB * 512;
for(;;)
{
if((mem = malloc(size)) != NULL)
{
free(mem);
printf("Successfully allocated and freed %llu bytes!\n", size);
}
else
{
printf("Unable to allocate %llu bytes. Resize and try again!\n", size);
break;
}
size += MB * 512;
}
return 0;
}
Here's the results:
Code:
Successfully allocated and freed 536870912 bytes!
Successfully allocated and freed 1073741824 bytes!
Successfully allocated and freed 1610612736 bytes!
Successfully allocated and freed 2147483648 bytes!
Unable to allocate 2684354560 bytes. Resize and try again!
It worked! It properly failed and reported it...
BTW, I only have 512mb ram. So this issue would actually come up if I were having to use too intensive of an application. I would much rather it give me a message like this than bail without saving my work.
But like I said, I haven't looked in the pulse code so I have no idea what context it's being used. But the generic argument that it's pointless not to bail from a failed malloc is wrong. Please don't write code that is going to destroy peoples work without warning.
Bookmarks