Exemplo n.º 1
0
static void *null_alloc(size_t size) {
  void *ret = NULL;

  if (size == 0) {
    /* Yes, this code is correct.
     *
     * The size argument is the originally requested amount of memory.
     * null_alloc() is called because smalloc() returned NULL.  But why,
     * exactly?  If the requested size is zero, then it may not have been
     * an error -- or it may be because the system is actually out of memory.
     * To differentiate, we do a malloc(0) call here if the requested size is
     * zero.  If malloc(0) returns NULL, then we really do have an error.
     */
    ret = malloc(size);
  }

  if (ret == NULL) {
    pr_log_pri(PR_LOG_ALERT, "Out of memory!");
#ifdef PR_USE_DEVEL
    if (debug_flags & PR_POOL_DEBUG_FL_OOM_DUMP_POOLS) {
      pr_pool_debug_memory(oom_printf);
    }
#endif
    exit(1);
  }

  return ret;
}
Exemplo n.º 2
0
static void null_alloc(void) {
  pr_log_pri(PR_LOG_ALERT, "Out of memory!");
#ifdef PR_USE_DEVEL
  if (debug_flags & PR_POOL_DEBUG_FL_OOM_DUMP_POOLS) {
    pr_pool_debug_memory(oom_printf);
  }
#endif

  exit(1);
}