From 2698d1d06050ce957f5157b84df189c9b211db65 Mon Sep 17 00:00:00 2001 From: "Dmitry V. Levin" Date: Mon, 26 Jun 2017 22:41:28 +0000 Subject: [PATCH] Unexport die_out_of_memory Print more specific error diagnostics than a generic "Out of memory" when an error happens outside xmalloc.c. * defs.h (die_out_of_memory): Remove prototype. * strace.c (strace_popen, init): Call perror_msg_and_die instead of die_out_of_memory. * unwind.c (unwind_tcb_init): Likewise. * xmalloc.c (die_out_of_memory): Add static qualifier. --- defs.h | 1 - strace.c | 4 ++-- unwind.c | 2 +- xmalloc.c | 2 +- 4 files changed, 4 insertions(+), 5 deletions(-) diff --git a/defs.h b/defs.h index 29a681b9..dcb4d947 100644 --- a/defs.h +++ b/defs.h @@ -393,7 +393,6 @@ void error_msg_and_help(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN; void perror_msg_and_die(const char *fmt, ...) ATTRIBUTE_FORMAT((printf, 1, 2)) ATTRIBUTE_NORETURN; -void die_out_of_memory(void) ATTRIBUTE_NORETURN; void *xmalloc(size_t size) ATTRIBUTE_MALLOC ATTRIBUTE_ALLOC_SIZE((1)); void *xcalloc(size_t nmemb, size_t size) diff --git a/strace.c b/strace.c index 3d5528af..2bb4ec15 100644 --- a/strace.c +++ b/strace.c @@ -566,7 +566,7 @@ strace_popen(const char *command) swap_uid(); fp = fdopen(fds[1], "w"); if (!fp) - die_out_of_memory(); + perror_msg_and_die("fdopen"); return fp; } @@ -1750,7 +1750,7 @@ init(int argc, char *argv[]) #endif case 'E': if (putenv(optarg) < 0) - die_out_of_memory(); + perror_msg_and_die("putenv"); break; case 'I': opt_intr = string_to_uint_upto(optarg, NUM_INTR_OPTS - 1); diff --git a/unwind.c b/unwind.c index 5279e6dc..919b63c3 100644 --- a/unwind.c +++ b/unwind.c @@ -113,7 +113,7 @@ unwind_tcb_init(struct tcb *tcp) tcp->libunwind_ui = _UPT_create(tcp->pid); if (!tcp->libunwind_ui) - die_out_of_memory(); + perror_msg_and_die("_UPT_create"); tcp->queue = xmalloc(sizeof(*tcp->queue)); tcp->queue->head = NULL; diff --git a/xmalloc.c b/xmalloc.c index 3ef48567..43e93eb3 100644 --- a/xmalloc.c +++ b/xmalloc.c @@ -27,7 +27,7 @@ #include "defs.h" -void die_out_of_memory(void) +static void die_out_of_memory(void) { static bool recursed;