]> sjero.net Git - wget/commitdiff
aprintf is calling memfatal function now instead of calling abort function
authorAlexander Dergachev <cy6erbr4in@gmail.com>
Wed, 9 Apr 2008 18:27:58 +0000 (22:27 +0400)
committerAlexander Dergachev <cy6erbr4in@gmail.com>
Wed, 9 Apr 2008 18:27:58 +0000 (22:27 +0400)
for consistency with xmalloc/xrealloc

src/utils.c
src/xmalloc.c
src/xmalloc.h

index 8c56d4dbf5772ae3f9dbf4e91c5f47960c35dd0c..3fd1435ec20d59326d20078006fbfacb02aeecfb 100644 (file)
@@ -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;
index 75ecf5ef1c9a93944358bcd9aedd34cd1aa410ba..aaf743df559bf05ee067e0960e4a9ce714b058b3 100644 (file)
@@ -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);
 }
 
index 67b97e6e9ac927b14ac3f132c5b4b525433dab27..ce326b1b7ae9300390cafd6b1d24783fbf1a3024 100644 (file)
@@ -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