From 79bd3057b1c6708db041023d02c9fdfbeb3ec08a Mon Sep 17 00:00:00 2001 From: Alexander Dergachev Date: Wed, 9 Apr 2008 22:27:58 +0400 Subject: [PATCH] aprintf is calling memfatal function now instead of calling abort function for consistency with xmalloc/xrealloc --- src/utils.c | 2 +- src/xmalloc.c | 22 ++++++++++++++++++---- src/xmalloc.h | 7 +++++++ 3 files changed, 26 insertions(+), 5 deletions(-) diff --git a/src/utils.c b/src/utils.c index 8c56d4db..3fd1435e 100644 --- a/src/utils.c +++ b/src/utils.c @@ -171,7 +171,7 @@ aprintf (const char *fmt, ...) ret = vasprintf (&str, fmt, args); va_end (args); if (ret < 0 && errno == ENOMEM) - abort (); /* for consistency with xmalloc/xrealloc */ + memfatal ("aprintf", UNKNOWN_ATTEMPTED_SIZE); /* for consistency with xmalloc/xrealloc */ else if (ret < 0) return NULL; return str; diff --git a/src/xmalloc.c b/src/xmalloc.c index 75ecf5ef..aaf743df 100644 --- a/src/xmalloc.c +++ b/src/xmalloc.c @@ -53,15 +53,29 @@ as that of the covered work. */ /* Croak the fatal memory error and bail out with non-zero exit status. */ -static void +void memfatal (const char *context, long attempted_size) { /* Make sure we don't try to store part of the log line, and thus call malloc. */ log_set_save_context (false); - logprintf (LOG_ALWAYS, - _("%s: %s: Failed to allocate %ld bytes; memory exhausted.\n"), - exec_name, context, attempted_size); + + /* We have different log outputs in different situations: + 1) output without bytes information + 2) output with bytes information */ + if (attempted_size == UNKNOWN_ATTEMPTED_SIZE) + { + logprintf (LOG_ALWAYS, + _("%s: %s: Failed to allocate enough memory; memory exhausted.\n"), + exec_name, context); + } + else + { + logprintf (LOG_ALWAYS, + _("%s: %s: Failed to allocate %ld bytes; memory exhausted.\n"), + exec_name, context, attempted_size); + } + exit (1); } diff --git a/src/xmalloc.h b/src/xmalloc.h index 67b97e6e..ce326b1b 100644 --- a/src/xmalloc.h +++ b/src/xmalloc.h @@ -31,6 +31,13 @@ as that of the covered work. */ #ifndef XMALLOC_H #define XMALLOC_H +/* Croak the fatal memory error and bail out with non-zero exit + status. */ +void memfatal (const char *context, long attempted_size); + +/* Constant is using when we don`t know attempted size exactly */ +#define UNKNOWN_ATTEMPTED_SIZE -3 + /* Define this to use Wget's builtin malloc debugging, which is crude but occasionally useful. It will make Wget a lot slower and larger, and susceptible to aborting if malloc_table overflows, so -- 2.39.2