From 243239d41a38ede7076d1796dd6e26a82336445f Mon Sep 17 00:00:00 2001 From: Eugene Syromiatnikov Date: Fri, 4 Aug 2017 08:43:16 +0200 Subject: [PATCH] unwind.c: non-fatal handling of asprintf error An error returned by asprintf is a poor excuse for dying. * unwind.c (asprintf_error_str): New string constant. (sprint_call_or_error): Replace error_msg_and_die() with perror_func_msg() and usage of asprintf_error_str for a return value. (queue_print): Free tmp->output line only if it is not asprintf_error_str. --- unwind.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/unwind.c b/unwind.c index 703df779..053561ad 100644 --- a/unwind.c +++ b/unwind.c @@ -90,6 +90,8 @@ static void delete_mmap_cache(struct tcb *tcp, const char *caller); static unw_addr_space_t libunwind_as; static unsigned int mmap_cache_generation; +static const char asprintf_error_str[] = "???"; + void unwind_init(void) { @@ -454,8 +456,10 @@ sprint_call_or_error(const char *binary_filename, else n = asprintf(&output_line, STACK_ENTRY_BUG_FMT, __func__); - if (n < 0) - error_msg_and_die("error in asprintf"); + if (n < 0) { + perror_func_msg("asprintf"); + output_line = (char *) asprintf_error_str; + } return output_line; } @@ -528,7 +532,9 @@ queue_print(struct queue_t *queue) tprints(tmp->output_line); line_ended(); - free(tmp->output_line); + if (tmp->output_line != asprintf_error_str) + free(tmp->output_line); + tmp->output_line = NULL; tmp->next = NULL; free(tmp);