On 01 Sep 2010, at 6:07 AM, dave b wrote:

What is the rational behind not checking the return value of
apr_palloc and apr_pcalloc?

The rationale is to not be forced to check for and handle hundreds of potential failure cases when you're probably doomed anyway.

The APR pools API gives you the apr_pool_abort_set() function, which specifies a function to call if the memory allocation fails. In the case of httpd, a function is registered which gracefully shuts down that particular server process if the allocation fails, and apr_palloc() is in the process guaranteed to never return NULL.

Obviously if you're not using APR from httpd, or if you're writing a library that depends on APR, and you haven't set an abort function, NULL will potentially be returned and you should check for and handle that case.

Regards,
Graham
--

Reply via email to