Carsten Breuer wrote:
> Hi Thomas, hi all
> 
> 
>> On a normal, modern operating system, (reasonably sized) mallocs should
>> never fail, as the system will start thrashing and killing off processes
>> long before malloc() fails.
> 
> Well, try:
> 
> for (int idx = 0; idx < 255; idx++)
> {
>      void *p = malloc(0xFFFFFFFF);
> }
> 

That's why I said "reasonably sized". If you malloc() inside a file 
parser, malloc() based on unverified user input, or malloc() huge 
buffers, adding a check is an absolute necessity.

These are cases with a clear action to take on error.

But adding a check to every random malloc(sizeof some_struct) is 
counter-productive. If a small malloc() fails, chances are that your 
error handler will fail, too.

Let the operating system take care of these cases.
_______________________________________________
Openocd-development mailing list
Openocd-development@lists.berlios.de
https://lists.berlios.de/mailman/listinfo/openocd-development

Reply via email to